Skip to content

Commit 37eec5c

Browse files
committed
Auto merge of #115698 - gurry:115143-ice-normalization-error, r=compiler-errors
Fix ICE in improper_ctypes_definitions lint Fix #115143
2 parents 58b4ebc + e7c5132 commit 37eec5c

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

compiler/rustc_lint/src/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,8 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
917917
// At this point, the field's type is known to be nonnull and the parent enum is Option-like.
918918
// If the computed size for the field and the enum are different, the nonnull optimization isn't
919919
// being applied (and we've got a problem somewhere).
920-
let compute_size_skeleton = |t| SizeSkeleton::compute(t, tcx, param_env).unwrap();
921-
if !compute_size_skeleton(ty).same_size(compute_size_skeleton(field_ty)) {
920+
let compute_size_skeleton = |t| SizeSkeleton::compute(t, tcx, param_env).ok();
921+
if !compute_size_skeleton(ty)?.same_size(compute_size_skeleton(field_ty)?) {
922922
bug!("improper_ctypes: Option nonnull optimization not applied?");
923923
}
924924

tests/ui/lint/lint-ctypes-94223.rs

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ enum BadUnion {
2424
type Foo = extern "C" fn([u8]);
2525
//~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe
2626

27+
pub trait FooTrait {
28+
type FooType;
29+
}
30+
31+
pub type Foo2<T> = extern "C" fn(Option<&<T as FooTrait>::FooType>);
32+
//~^ ERROR `extern` fn uses type `Option<&<T as FooTrait>::FooType>`, which is not FFI-safe
33+
2734
pub struct FfiUnsafe;
2835

2936
#[allow(improper_ctypes_definitions)]

tests/ui/lint/lint-ctypes-94223.stderr

+18-9
Original file line numberDiff line numberDiff line change
@@ -66,61 +66,70 @@ LL | type Foo = extern "C" fn([u8]);
6666
= help: consider using a raw pointer instead
6767
= note: slices have no C equivalent
6868

69+
error: `extern` fn uses type `Option<&<T as FooTrait>::FooType>`, which is not FFI-safe
70+
--> $DIR/lint-ctypes-94223.rs:31:20
71+
|
72+
LL | pub type Foo2<T> = extern "C" fn(Option<&<T as FooTrait>::FooType>);
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
74+
|
75+
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
76+
= note: enum has no representation hint
77+
6978
error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
70-
--> $DIR/lint-ctypes-94223.rs:34:17
79+
--> $DIR/lint-ctypes-94223.rs:41:17
7180
|
7281
LL | pub static BAD: extern "C" fn(FfiUnsafe) = f;
7382
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
7483
|
7584
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
7685
= note: this struct has unspecified layout
7786
note: the type is defined here
78-
--> $DIR/lint-ctypes-94223.rs:27:1
87+
--> $DIR/lint-ctypes-94223.rs:34:1
7988
|
8089
LL | pub struct FfiUnsafe;
8190
| ^^^^^^^^^^^^^^^^^^^^
8291

8392
error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
84-
--> $DIR/lint-ctypes-94223.rs:37:30
93+
--> $DIR/lint-ctypes-94223.rs:44:30
8594
|
8695
LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f);
8796
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
8897
|
8998
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
9099
= note: this struct has unspecified layout
91100
note: the type is defined here
92-
--> $DIR/lint-ctypes-94223.rs:27:1
101+
--> $DIR/lint-ctypes-94223.rs:34:1
93102
|
94103
LL | pub struct FfiUnsafe;
95104
| ^^^^^^^^^^^^^^^^^^^^
96105

97106
error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
98-
--> $DIR/lint-ctypes-94223.rs:37:56
107+
--> $DIR/lint-ctypes-94223.rs:44:56
99108
|
100109
LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f);
101110
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
102111
|
103112
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
104113
= note: this struct has unspecified layout
105114
note: the type is defined here
106-
--> $DIR/lint-ctypes-94223.rs:27:1
115+
--> $DIR/lint-ctypes-94223.rs:34:1
107116
|
108117
LL | pub struct FfiUnsafe;
109118
| ^^^^^^^^^^^^^^^^^^^^
110119

111120
error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
112-
--> $DIR/lint-ctypes-94223.rs:41:22
121+
--> $DIR/lint-ctypes-94223.rs:48:22
113122
|
114123
LL | pub const BAD_CONST: extern "C" fn(FfiUnsafe) = f;
115124
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
116125
|
117126
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
118127
= note: this struct has unspecified layout
119128
note: the type is defined here
120-
--> $DIR/lint-ctypes-94223.rs:27:1
129+
--> $DIR/lint-ctypes-94223.rs:34:1
121130
|
122131
LL | pub struct FfiUnsafe;
123132
| ^^^^^^^^^^^^^^^^^^^^
124133

125-
error: aborting due to 11 previous errors
134+
error: aborting due to 12 previous errors
126135

0 commit comments

Comments
 (0)