Skip to content

Commit b2195b1

Browse files
committed
lint ImproperCtypes: move code to new place, prior to full rewrite
1 parent d5dbf9a commit b2195b1

40 files changed

+1363
-1373
lines changed

compiler/rustc_lint/src/foreign_modules.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ impl ClashingExternDeclarations {
136136
ty::TypingEnv::non_body_analysis(tcx, this_fi.owner_id),
137137
existing_decl_ty,
138138
this_decl_ty,
139-
types::CItemKind::Declaration,
140139
) {
141140
let orig = name_of_extern_decl(tcx, existing_did);
142141

@@ -214,10 +213,9 @@ fn structurally_same_type<'tcx>(
214213
typing_env: ty::TypingEnv<'tcx>,
215214
a: Ty<'tcx>,
216215
b: Ty<'tcx>,
217-
ckind: types::CItemKind,
218216
) -> bool {
219217
let mut seen_types = UnordSet::default();
220-
let result = structurally_same_type_impl(&mut seen_types, tcx, typing_env, a, b, ckind);
218+
let result = structurally_same_type_impl(&mut seen_types, tcx, typing_env, a, b);
221219
if cfg!(debug_assertions) && result {
222220
// Sanity-check: must have same ABI, size and alignment.
223221
// `extern` blocks cannot be generic, so we'll always get a layout here.
@@ -236,7 +234,6 @@ fn structurally_same_type_impl<'tcx>(
236234
typing_env: ty::TypingEnv<'tcx>,
237235
a: Ty<'tcx>,
238236
b: Ty<'tcx>,
239-
ckind: types::CItemKind,
240237
) -> bool {
241238
debug!("structurally_same_type_impl(tcx, a = {:?}, b = {:?})", a, b);
242239

@@ -307,33 +304,26 @@ fn structurally_same_type_impl<'tcx>(
307304
typing_env,
308305
tcx.type_of(a_did).instantiate(tcx, a_gen_args),
309306
tcx.type_of(b_did).instantiate(tcx, b_gen_args),
310-
ckind,
311307
)
312308
},
313309
)
314310
}
315311
(ty::Array(a_ty, a_len), ty::Array(b_ty, b_len)) => {
316312
// For arrays, we also check the length.
317313
a_len == b_len
318-
&& structurally_same_type_impl(
319-
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
320-
)
314+
&& structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty)
321315
}
322316
(ty::Slice(a_ty), ty::Slice(b_ty)) => {
323-
structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty, ckind)
317+
structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty)
324318
}
325319
(ty::RawPtr(a_ty, a_mutbl), ty::RawPtr(b_ty, b_mutbl)) => {
326320
a_mutbl == b_mutbl
327-
&& structurally_same_type_impl(
328-
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
329-
)
321+
&& structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty)
330322
}
331323
(ty::Ref(_a_region, a_ty, a_mut), ty::Ref(_b_region, b_ty, b_mut)) => {
332324
// For structural sameness, we don't need the region to be same.
333325
a_mut == b_mut
334-
&& structurally_same_type_impl(
335-
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
336-
)
326+
&& structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty)
337327
}
338328
(ty::FnDef(..), ty::FnDef(..)) => {
339329
let a_poly_sig = a.fn_sig(tcx);
@@ -347,15 +337,14 @@ fn structurally_same_type_impl<'tcx>(
347337
(a_sig.abi, a_sig.safety, a_sig.c_variadic)
348338
== (b_sig.abi, b_sig.safety, b_sig.c_variadic)
349339
&& a_sig.inputs().iter().eq_by(b_sig.inputs().iter(), |a, b| {
350-
structurally_same_type_impl(seen_types, tcx, typing_env, *a, *b, ckind)
340+
structurally_same_type_impl(seen_types, tcx, typing_env, *a, *b)
351341
})
352342
&& structurally_same_type_impl(
353343
seen_types,
354344
tcx,
355345
typing_env,
356346
a_sig.output(),
357347
b_sig.output(),
358-
ckind,
359348
)
360349
}
361350
(ty::Tuple(..), ty::Tuple(..)) => {
@@ -383,14 +372,14 @@ fn structurally_same_type_impl<'tcx>(
383372
// An Adt and a primitive or pointer type. This can be FFI-safe if non-null
384373
// enum layout optimisation is being applied.
385374
(ty::Adt(..) | ty::Pat(..), _) if is_primitive_or_pointer(b) => {
386-
if let Some(a_inner) = types::repr_nullable_ptr(tcx, typing_env, a, ckind) {
375+
if let Some(a_inner) = types::repr_nullable_ptr(tcx, typing_env, a) {
387376
a_inner == b
388377
} else {
389378
false
390379
}
391380
}
392381
(_, ty::Adt(..) | ty::Pat(..)) if is_primitive_or_pointer(a) => {
393-
if let Some(b_inner) = types::repr_nullable_ptr(tcx, typing_env, b, ckind) {
382+
if let Some(b_inner) = types::repr_nullable_ptr(tcx, typing_env, b) {
394383
b_inner == a
395384
} else {
396385
false

0 commit comments

Comments
 (0)