about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2025-07-21 00:11:42 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2025-07-25 23:07:31 +0000
commitec8146477e90337517b3483b84738eb5dfe53770 (patch)
tree337503fe31223b0521e710d52a66ec3a5ca7ca8c
parent832207862a2e74ec51879b072fd0dd2599395b91 (diff)
downloadrust-ec8146477e90337517b3483b84738eb5dfe53770.tar.gz
rust-ec8146477e90337517b3483b84738eb5dfe53770.zip
Look at layout for completeness.
-rw-r--r--compiler/rustc_mir_build/src/builder/expr/as_constant.rs14
-rw-r--r--tests/ui/coroutine/layout-error.rs2
-rw-r--r--tests/ui/coroutine/layout-error.stderr52
3 files changed, 60 insertions, 8 deletions
diff --git a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs
index 5eb324f4b51..92935dfc97a 100644
--- a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs
+++ b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs
@@ -1,6 +1,6 @@
 //! See docs in build/expr/mod.rs
 
-use rustc_abi::Size;
+use rustc_abi::{BackendRepr, Size};
 use rustc_ast as ast;
 use rustc_hir::LangItem;
 use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, LitToConstInput, Scalar};
@@ -83,8 +83,10 @@ pub(crate) fn as_constant_inner<'tcx>(
             ConstOperand { user_ty: None, span, const_ }
         }
         ExprKind::StaticRef { alloc_id, ty, .. } => {
-            let pointee = ty.builtin_deref(true).expect("StaticRef's type must be pointer");
-            let const_ = if pointee.is_sized(tcx, typing_env) {
+            let layout = tcx.layout_of(typing_env.as_query_input(ty));
+            let const_ = if let Ok(layout) = layout
+                && let BackendRepr::Scalar(..) = layout.backend_repr
+            {
                 let const_val = ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &tcx));
                 Const::Val(const_val, ty)
             } else {
@@ -92,8 +94,10 @@ pub(crate) fn as_constant_inner<'tcx>(
                 // This should be reported by wfcheck on the static itself.
                 // Still, producing a single scalar constant would be inconsistent, as pointers to
                 // non-`Sized` types are scalar pairs. Avoid an ICE by producing an error constant.
-                let guar =
-                    tcx.dcx().span_delayed_bug(span, format!("static's type `{ty}` is not Sized"));
+                let guar = tcx.dcx().span_delayed_bug(
+                    span,
+                    format!("pointer to static's type `{ty}` is not scalar"),
+                );
                 Const::Ty(ty, ty::Const::new_error(tcx, guar))
             };
 
diff --git a/tests/ui/coroutine/layout-error.rs b/tests/ui/coroutine/layout-error.rs
index 6cf32134025..2ee0bd81619 100644
--- a/tests/ui/coroutine/layout-error.rs
+++ b/tests/ui/coroutine/layout-error.rs
@@ -17,6 +17,8 @@ impl<F: Future> Task<F> {
 }
 
 pub type F = impl Future;
+//~^ ERROR cycle detected when computing type of `F::{opaque#0}`
+
 #[define_opaque(F)]
 fn foo()
 where
diff --git a/tests/ui/coroutine/layout-error.stderr b/tests/ui/coroutine/layout-error.stderr
index 91e35216435..057ac36b849 100644
--- a/tests/ui/coroutine/layout-error.stderr
+++ b/tests/ui/coroutine/layout-error.stderr
@@ -1,9 +1,55 @@
 error[E0425]: cannot find value `Foo` in this scope
-  --> $DIR/layout-error.rs:26:17
+  --> $DIR/layout-error.rs:28:17
    |
 LL |         let a = Foo;
    |                 ^^^ not found in this scope
 
-error: aborting due to 1 previous error
+error[E0391]: cycle detected when computing type of `F::{opaque#0}`
+  --> $DIR/layout-error.rs:19:14
+   |
+LL | pub type F = impl Future;
+   |              ^^^^^^^^^^^
+   |
+note: ...which requires computing type of opaque `F::{opaque#0}`...
+  --> $DIR/layout-error.rs:19:14
+   |
+LL | pub type F = impl Future;
+   |              ^^^^^^^^^^^
+note: ...which requires borrow-checking `foo`...
+  --> $DIR/layout-error.rs:23:1
+   |
+LL | / fn foo()
+LL | | where
+LL | |     F:,
+   | |_______^
+note: ...which requires promoting constants in MIR for `foo`...
+  --> $DIR/layout-error.rs:23:1
+   |
+LL | / fn foo()
+LL | | where
+LL | |     F:,
+   | |_______^
+note: ...which requires checking if `foo` contains FFI-unwind calls...
+  --> $DIR/layout-error.rs:23:1
+   |
+LL | / fn foo()
+LL | | where
+LL | |     F:,
+   | |_______^
+note: ...which requires building MIR for `foo`...
+  --> $DIR/layout-error.rs:23:1
+   |
+LL | / fn foo()
+LL | | where
+LL | |     F:,
+   | |_______^
+   = note: ...which requires computing layout of `&Task<F>`...
+   = note: ...which requires normalizing `&Task<F>`...
+   = note: ...which again requires computing type of `F::{opaque#0}`, completing the cycle
+   = note: cycle used when normalizing `Task<F>`
+   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
+
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0425`.
+Some errors have detailed explanations: E0391, E0425.
+For more information about an error, try `rustc --explain E0391`.