Don't ICE when computing ctype's repr_nullable_ptr for possibly-unsized ty
This commit is contained in:
parent
f00c139998
commit
086cf34634
@ -923,7 +923,12 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
|
||||
}
|
||||
|
||||
// Return the nullable type this Option-like enum can be safely represented with.
|
||||
let field_ty_abi = &tcx.layout_of(param_env.and(field_ty)).unwrap().abi;
|
||||
let field_ty_layout = tcx.layout_of(param_env.and(field_ty));
|
||||
if field_ty_layout.is_err() && !field_ty.has_non_region_param() {
|
||||
bug!("should be able to compute the layout of non-polymorphic type");
|
||||
}
|
||||
|
||||
let field_ty_abi = &field_ty_layout.ok()?.abi;
|
||||
if let Abi::Scalar(field_ty_scalar) = field_ty_abi {
|
||||
match field_ty_scalar.valid_range(&tcx) {
|
||||
WrappingRange { start: 0, end }
|
||||
|
8
tests/ui/lint/lint-ctypes-option-nonnull-unsized.rs
Normal file
8
tests/ui/lint/lint-ctypes-option-nonnull-unsized.rs
Normal file
@ -0,0 +1,8 @@
|
||||
#![deny(improper_ctypes_definitions)]
|
||||
|
||||
extern "C" fn foo<T: ?Sized + 'static>() -> Option<&'static T> {
|
||||
//~^ ERROR `extern` fn uses type `Option<&T>`, which is not FFI-safe
|
||||
None
|
||||
}
|
||||
|
||||
fn main() {}
|
16
tests/ui/lint/lint-ctypes-option-nonnull-unsized.stderr
Normal file
16
tests/ui/lint/lint-ctypes-option-nonnull-unsized.stderr
Normal file
@ -0,0 +1,16 @@
|
||||
error: `extern` fn uses type `Option<&T>`, which is not FFI-safe
|
||||
--> $DIR/lint-ctypes-option-nonnull-unsized.rs:3:45
|
||||
|
|
||||
LL | extern "C" fn foo<T: ?Sized + 'static>() -> Option<&'static T> {
|
||||
| ^^^^^^^^^^^^^^^^^^ not FFI-safe
|
||||
|
|
||||
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
|
||||
= note: enum has no representation hint
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-ctypes-option-nonnull-unsized.rs:1:9
|
||||
|
|
||||
LL | #![deny(improper_ctypes_definitions)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user