Skip to content

Commit 3289254

Browse files
authored
Unrolled build for rust-lang#129527
Rollup merge of rust-lang#129527 - compiler-errors:lint-nit, r=Nadrieril Don't use `TyKind` in a lint Allows us to remove an inherent method from `TyKind` from the type ir crate.
2 parents fa72f07 + 42a901a commit 3289254

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

compiler/rustc_lint/src/foreign_modules.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ fn structurally_same_type_impl<'tcx>(
265265
} else {
266266
// Do a full, depth-first comparison between the two.
267267
use rustc_type_ir::TyKind::*;
268-
let a_kind = a.kind();
269-
let b_kind = b.kind();
270268

271269
let compare_layouts = |a, b| -> Result<bool, &'tcx LayoutError<'tcx>> {
272270
debug!("compare_layouts({:?}, {:?})", a, b);
@@ -281,12 +279,11 @@ fn structurally_same_type_impl<'tcx>(
281279
Ok(a_layout == b_layout)
282280
};
283281

284-
#[allow(rustc::usage_of_ty_tykind)]
285282
let is_primitive_or_pointer =
286-
|kind: &ty::TyKind<'_>| kind.is_primitive() || matches!(kind, RawPtr(..) | Ref(..));
283+
|ty: Ty<'tcx>| ty.is_primitive() || matches!(ty.kind(), RawPtr(..) | Ref(..));
287284

288285
ensure_sufficient_stack(|| {
289-
match (a_kind, b_kind) {
286+
match (a.kind(), b.kind()) {
290287
(Adt(a_def, _), Adt(b_def, _)) => {
291288
// We can immediately rule out these types as structurally same if
292289
// their layouts differ.
@@ -382,17 +379,21 @@ fn structurally_same_type_impl<'tcx>(
382379

383380
// An Adt and a primitive or pointer type. This can be FFI-safe if non-null
384381
// enum layout optimisation is being applied.
385-
(Adt(..), other_kind) | (other_kind, Adt(..))
386-
if is_primitive_or_pointer(other_kind) =>
387-
{
388-
let (primitive, adt) =
389-
if is_primitive_or_pointer(a.kind()) { (a, b) } else { (b, a) };
390-
if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, adt, ckind) {
391-
ty == primitive
382+
(Adt(..), _) if is_primitive_or_pointer(b) => {
383+
if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, a, ckind) {
384+
ty == b
392385
} else {
393386
compare_layouts(a, b).unwrap_or(false)
394387
}
395388
}
389+
(_, Adt(..)) if is_primitive_or_pointer(a) => {
390+
if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, b, ckind) {
391+
ty == a
392+
} else {
393+
compare_layouts(a, b).unwrap_or(false)
394+
}
395+
}
396+
396397
// Otherwise, just compare the layouts. This may fail to lint for some
397398
// incompatible types, but at the very least, will stop reads into
398399
// uninitialised memory.

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl<'tcx> Ty<'tcx> {
10001000

10011001
#[inline]
10021002
pub fn is_primitive(self) -> bool {
1003-
self.kind().is_primitive()
1003+
matches!(self.kind(), Bool | Char | Int(_) | Uint(_) | Float(_))
10041004
}
10051005

10061006
#[inline]

compiler/rustc_type_ir/src/ty_kind.rs

-7
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,6 @@ pub enum TyKind<I: Interner> {
254254
Error(I::ErrorGuaranteed),
255255
}
256256

257-
impl<I: Interner> TyKind<I> {
258-
#[inline]
259-
pub fn is_primitive(&self) -> bool {
260-
matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
261-
}
262-
}
263-
264257
// This is manually implemented because a derive would require `I: Debug`
265258
impl<I: Interner> fmt::Debug for TyKind<I> {
266259
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

0 commit comments

Comments
 (0)