Skip to content

Commit 1a23d74

Browse files
committed
Look at layout for completeness.
1 parent 8322078 commit 1a23d74

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

compiler/rustc_mir_build/src/builder/expr/as_constant.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! See docs in build/expr/mod.rs
22
3-
use rustc_abi::Size;
3+
use rustc_abi::{BackendRepr, Size};
44
use rustc_ast as ast;
55
use rustc_hir::LangItem;
66
use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, LitToConstInput, Scalar};
@@ -83,8 +83,10 @@ pub(crate) fn as_constant_inner<'tcx>(
8383
ConstOperand { user_ty: None, span, const_ }
8484
}
8585
ExprKind::StaticRef { alloc_id, ty, .. } => {
86-
let pointee = ty.builtin_deref(true).expect("StaticRef's type must be pointer");
87-
let const_ = if pointee.is_sized(tcx, typing_env) {
86+
let layout = tcx.layout_of(typing_env.as_query_input(ty));
87+
let const_ = if let Ok(layout) = layout
88+
&& let BackendRepr::Scalar(..) = layout.backend_repr
89+
{
8890
let const_val = ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &tcx));
8991
Const::Val(const_val, ty)
9092
} else {
@@ -93,7 +95,7 @@ pub(crate) fn as_constant_inner<'tcx>(
9395
// Still, producing a single scalar constant would be inconsistent, as pointers to
9496
// non-`Sized` types are scalar pairs. Avoid an ICE by producing an error constant.
9597
let guar =
96-
tcx.dcx().span_delayed_bug(span, format!("static's type `{ty}` is not Sized"));
98+
tcx.dcx().span_delayed_bug(span, format!("static's type `{ty}` is not scalar"));
9799
Const::Ty(ty, ty::Const::new_error(tcx, guar))
98100
};
99101

tests/ui/coroutine/layout-error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ impl<F: Future> Task<F> {
1717
}
1818

1919
pub type F = impl Future;
20+
//~^ ERROR cycle detected when computing type of `F::{opaque#0}`
21+
2022
#[define_opaque(F)]
2123
fn foo()
2224
where
Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,55 @@
11
error[E0425]: cannot find value `Foo` in this scope
2-
--> $DIR/layout-error.rs:26:17
2+
--> $DIR/layout-error.rs:28:17
33
|
44
LL | let a = Foo;
55
| ^^^ not found in this scope
66

7-
error: aborting due to 1 previous error
7+
error[E0391]: cycle detected when computing type of `F::{opaque#0}`
8+
--> $DIR/layout-error.rs:19:14
9+
|
10+
LL | pub type F = impl Future;
11+
| ^^^^^^^^^^^
12+
|
13+
note: ...which requires computing type of opaque `F::{opaque#0}`...
14+
--> $DIR/layout-error.rs:19:14
15+
|
16+
LL | pub type F = impl Future;
17+
| ^^^^^^^^^^^
18+
note: ...which requires borrow-checking `foo`...
19+
--> $DIR/layout-error.rs:23:1
20+
|
21+
LL | / fn foo()
22+
LL | | where
23+
LL | | F:,
24+
| |_______^
25+
note: ...which requires promoting constants in MIR for `foo`...
26+
--> $DIR/layout-error.rs:23:1
27+
|
28+
LL | / fn foo()
29+
LL | | where
30+
LL | | F:,
31+
| |_______^
32+
note: ...which requires checking if `foo` contains FFI-unwind calls...
33+
--> $DIR/layout-error.rs:23:1
34+
|
35+
LL | / fn foo()
36+
LL | | where
37+
LL | | F:,
38+
| |_______^
39+
note: ...which requires building MIR for `foo`...
40+
--> $DIR/layout-error.rs:23:1
41+
|
42+
LL | / fn foo()
43+
LL | | where
44+
LL | | F:,
45+
| |_______^
46+
= note: ...which requires computing layout of `&Task<F>`...
47+
= note: ...which requires normalizing `&Task<F>`...
48+
= note: ...which again requires computing type of `F::{opaque#0}`, completing the cycle
49+
= note: cycle used when normalizing `Task<F>`
50+
= 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
51+
52+
error: aborting due to 2 previous errors
853

9-
For more information about this error, try `rustc --explain E0425`.
54+
Some errors have detailed explanations: E0391, E0425.
55+
For more information about an error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)