Skip to content

Commit f7bf9f1

Browse files
authored
Unrolled build for rust-lang#115631
Rollup merge of rust-lang#115631 - compiler-errors:ctypes-unsized, r=davidtwco Don't ICE when computing ctype's `repr_nullable_ptr` for possibly-unsized ty We may not always be able to compute the layout of a type like `&T` when `T: ?Sized`, even if we're able to estimate its size skeleton. r? davidtwco Fixes rust-lang#115628
2 parents e2b3676 + 086cf34 commit f7bf9f1

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/rustc_lint/src/types.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,12 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
923923
}
924924

925925
// Return the nullable type this Option-like enum can be safely represented with.
926-
let field_ty_abi = &tcx.layout_of(param_env.and(field_ty)).unwrap().abi;
926+
let field_ty_layout = tcx.layout_of(param_env.and(field_ty));
927+
if field_ty_layout.is_err() && !field_ty.has_non_region_param() {
928+
bug!("should be able to compute the layout of non-polymorphic type");
929+
}
930+
931+
let field_ty_abi = &field_ty_layout.ok()?.abi;
927932
if let Abi::Scalar(field_ty_scalar) = field_ty_abi {
928933
match field_ty_scalar.valid_range(&tcx) {
929934
WrappingRange { start: 0, end }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![deny(improper_ctypes_definitions)]
2+
3+
extern "C" fn foo<T: ?Sized + 'static>() -> Option<&'static T> {
4+
//~^ ERROR `extern` fn uses type `Option<&T>`, which is not FFI-safe
5+
None
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: `extern` fn uses type `Option<&T>`, which is not FFI-safe
2+
--> $DIR/lint-ctypes-option-nonnull-unsized.rs:3:45
3+
|
4+
LL | extern "C" fn foo<T: ?Sized + 'static>() -> Option<&'static T> {
5+
| ^^^^^^^^^^^^^^^^^^ not FFI-safe
6+
|
7+
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
8+
= note: enum has no representation hint
9+
note: the lint level is defined here
10+
--> $DIR/lint-ctypes-option-nonnull-unsized.rs:1:9
11+
|
12+
LL | #![deny(improper_ctypes_definitions)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+

0 commit comments

Comments
 (0)