mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
ImproperCTypes: reorder simple type checks
Another interal change that shouldn't impact rustc users. the list of simpler type-based decisions made by `visit_type` are reordered and are given better documentation.
This commit is contained in:
@@ -600,19 +600,23 @@ fn visit_type(&mut self, state: VisitorState, ty: Ty<'tcx>) -> FfiResult<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
ty::Char => FfiUnsafe {
|
||||
// Pattern types are just extra invariants on the type that you need to uphold,
|
||||
// but only the base type is relevant for being representable in FFI.
|
||||
// (note: this lint was written when pattern types could only be integers constrained to ranges)
|
||||
ty::Pat(pat_ty, _) => self.visit_type(state, pat_ty),
|
||||
|
||||
// types which likely have a stable representation, if the target architecture defines those
|
||||
// note: before rust 1.77, 128-bit ints were not FFI-safe on x86_64
|
||||
ty::Int(..) | ty::Uint(..) | ty::Float(..) => FfiResult::FfiSafe,
|
||||
|
||||
ty::Bool => FfiResult::FfiSafe,
|
||||
|
||||
ty::Char => FfiResult::FfiUnsafe {
|
||||
ty,
|
||||
reason: msg!("the `char` type has no C equivalent"),
|
||||
help: Some(msg!("consider using `u32` or `libc::wchar_t` instead")),
|
||||
},
|
||||
|
||||
// It's just extra invariants on the type that you need to uphold,
|
||||
// but only the base type is relevant for being representable in FFI.
|
||||
ty::Pat(base, ..) => self.visit_type(state, base),
|
||||
|
||||
// Primitive types with a stable representation.
|
||||
ty::Bool | ty::Int(..) | ty::Uint(..) | ty::Float(..) | ty::Never => FfiSafe,
|
||||
|
||||
ty::Slice(_) => FfiUnsafe {
|
||||
ty,
|
||||
reason: msg!("slices have no C equivalent"),
|
||||
@@ -687,6 +691,8 @@ fn visit_type(&mut self, state: VisitorState, ty: Ty<'tcx>) -> FfiResult<'tcx> {
|
||||
|
||||
ty::Foreign(..) => FfiSafe,
|
||||
|
||||
ty::Never => FfiSafe,
|
||||
|
||||
// While opaque types are checked for earlier, if a projection in a struct field
|
||||
// normalizes to an opaque type, then it will reach this branch.
|
||||
ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
|
||||
|
||||
Reference in New Issue
Block a user