Skip to content

Commit 071780d

Browse files
committed
lint ImproperCtypes: move code to new place, prior to full rewrite
1 parent 4680cb1 commit 071780d

38 files changed

+1375
-1380
lines changed

compiler/rustc_lint/src/foreign_modules.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ impl ClashingExternDeclarations {
134134
ty::TypingEnv::non_body_analysis(tcx, this_fi.owner_id),
135135
existing_decl_ty,
136136
this_decl_ty,
137-
types::CItemKind::Declaration,
138137
) {
139138
let orig = name_of_extern_decl(tcx, existing_did);
140139

@@ -208,10 +207,9 @@ fn structurally_same_type<'tcx>(
208207
typing_env: ty::TypingEnv<'tcx>,
209208
a: Ty<'tcx>,
210209
b: Ty<'tcx>,
211-
ckind: types::CItemKind,
212210
) -> bool {
213211
let mut seen_types = UnordSet::default();
214-
let result = structurally_same_type_impl(&mut seen_types, tcx, typing_env, a, b, ckind);
212+
let result = structurally_same_type_impl(&mut seen_types, tcx, typing_env, a, b);
215213
if cfg!(debug_assertions) && result {
216214
// Sanity-check: must have same ABI, size and alignment.
217215
// `extern` blocks cannot be generic, so we'll always get a layout here.
@@ -230,7 +228,6 @@ fn structurally_same_type_impl<'tcx>(
230228
typing_env: ty::TypingEnv<'tcx>,
231229
a: Ty<'tcx>,
232230
b: Ty<'tcx>,
233-
ckind: types::CItemKind,
234231
) -> bool {
235232
debug!("structurally_same_type_impl(tcx, a = {:?}, b = {:?})", a, b);
236233

@@ -306,33 +303,26 @@ fn structurally_same_type_impl<'tcx>(
306303
typing_env,
307304
tcx.type_of(a_did).instantiate(tcx, a_gen_args),
308305
tcx.type_of(b_did).instantiate(tcx, b_gen_args),
309-
ckind,
310306
)
311307
},
312308
)
313309
}
314310
(Array(a_ty, a_len), Array(b_ty, b_len)) => {
315311
// For arrays, we also check the length.
316312
a_len == b_len
317-
&& structurally_same_type_impl(
318-
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
319-
)
313+
&& structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty)
320314
}
321315
(Slice(a_ty), Slice(b_ty)) => {
322-
structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty, ckind)
316+
structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty)
323317
}
324318
(RawPtr(a_ty, a_mutbl), RawPtr(b_ty, b_mutbl)) => {
325319
a_mutbl == b_mutbl
326-
&& structurally_same_type_impl(
327-
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
328-
)
320+
&& structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty)
329321
}
330322
(Ref(_a_region, a_ty, a_mut), Ref(_b_region, b_ty, b_mut)) => {
331323
// For structural sameness, we don't need the region to be same.
332324
a_mut == b_mut
333-
&& structurally_same_type_impl(
334-
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
335-
)
325+
&& structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty)
336326
}
337327
(FnDef(..), FnDef(..)) => {
338328
let a_poly_sig = a.fn_sig(tcx);
@@ -346,15 +336,14 @@ fn structurally_same_type_impl<'tcx>(
346336
(a_sig.abi, a_sig.safety, a_sig.c_variadic)
347337
== (b_sig.abi, b_sig.safety, b_sig.c_variadic)
348338
&& a_sig.inputs().iter().eq_by(b_sig.inputs().iter(), |a, b| {
349-
structurally_same_type_impl(seen_types, tcx, typing_env, *a, *b, ckind)
339+
structurally_same_type_impl(seen_types, tcx, typing_env, *a, *b)
350340
})
351341
&& structurally_same_type_impl(
352342
seen_types,
353343
tcx,
354344
typing_env,
355345
a_sig.output(),
356346
b_sig.output(),
357-
ckind,
358347
)
359348
}
360349
(Tuple(..), Tuple(..)) => {
@@ -379,14 +368,14 @@ fn structurally_same_type_impl<'tcx>(
379368
// An Adt and a primitive or pointer type. This can be FFI-safe if non-null
380369
// enum layout optimisation is being applied.
381370
(Adt(..), _) if is_primitive_or_pointer(b) => {
382-
if let Some(a_inner) = types::repr_nullable_ptr(tcx, typing_env, a, ckind) {
371+
if let Some(a_inner) = types::repr_nullable_ptr(tcx, typing_env, a) {
383372
a_inner == b
384373
} else {
385374
false
386375
}
387376
}
388377
(_, Adt(..)) if is_primitive_or_pointer(a) => {
389-
if let Some(b_inner) = types::repr_nullable_ptr(tcx, typing_env, b, ckind) {
378+
if let Some(b_inner) = types::repr_nullable_ptr(tcx, typing_env, b) {
390379
b_inner == a
391380
} else {
392381
false

0 commit comments

Comments
 (0)