diff options
| author | bors <bors@rust-lang.org> | 2021-02-10 12:56:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-10 12:56:09 +0000 |
| commit | 07194ffcd25b0871ce560b9f702e52db27ac9f77 (patch) | |
| tree | 2a2d473cf33b93ed3f7c310bbcc07a79b69ddb9b /compiler | |
| parent | 218bf8d7657e1aadf6f499651078f3710df20c7b (diff) | |
| parent | 8fc246251fad28715493d240e6a63a0db237ce7a (diff) | |
| download | rust-07194ffcd25b0871ce560b9f702e52db27ac9f77.tar.gz rust-07194ffcd25b0871ce560b9f702e52db27ac9f77.zip | |
Auto merge of #79804 - tmiasko:improper-ctypes-no-niche, r=pnkfelix
Types with a hidden niche are not known to be non-null Fixes #79787.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lint/src/types.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 784b36c2837..af0f5565572 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -672,7 +672,7 @@ pub fn transparent_newtype_field<'a, 'tcx>( } /// Is type known to be non-null? -crate fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: CItemKind) -> bool { +fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: CItemKind) -> bool { let tcx = cx.tcx; match ty.kind() { ty::FnPtr(_) => true, @@ -685,6 +685,12 @@ crate fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: C return true; } + // Types with a `#[repr(no_niche)]` attribute have their niche hidden. + // The attribute is used by the UnsafeCell for example (the only use so far). + if def.repr.hide_niche() { + return false; + } + for variant in &def.variants { if let Some(field) = transparent_newtype_field(cx.tcx, variant) { if ty_is_known_nonnull(cx, field.ty(tcx, substs), mode) { |
