Skip to content

Commit 1e5c14d

Browse files
committed
try putting the can_be_expressed_as_pointer_cast at the top and find that we still get an ICE
1 parent b4ecee9 commit 1e5c14d

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

src/tools/clippy/clippy_lints/src/transmute.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,26 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
330330
let from_ty = cx.typeck_results().expr_ty(&args[0]);
331331
let to_ty = cx.typeck_results().expr_ty(e);
332332

333+
if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) {
334+
span_lint_and_then(
335+
cx,
336+
TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
337+
e.span,
338+
&format!(
339+
"transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
340+
from_ty,
341+
to_ty
342+
),
343+
|diag| {
344+
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
345+
let sugg = format!("{} as {}", arg, to_ty);
346+
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
347+
}
348+
}
349+
);
350+
return
351+
}
352+
333353
match (&from_ty.kind, &to_ty.kind) {
334354
_ if from_ty == to_ty => span_lint(
335355
cx,
@@ -626,25 +646,9 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
626646
);
627647
}
628648
},
629-
_ => {},
630-
}
631-
if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) {
632-
span_lint_and_then(
633-
cx,
634-
TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
635-
e.span,
636-
&format!(
637-
"transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
638-
from_ty,
639-
to_ty
640-
),
641-
|diag| {
642-
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
643-
let sugg = format!("{} as {}", arg, to_ty);
644-
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
645-
}
646-
}
647-
)
649+
_ => {
650+
return;
651+
},
648652
}
649653
}
650654
}

src/tools/clippy/tests/ui/transmute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(dead_code)]
2+
#![allow(clippy::transmutes_expressible_as_ptr_casts)]
23

34
extern crate core;
4-
55
use std::mem::transmute as my_transmute;
66
use std::vec::Vec as MyVec;
77

src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::transmute_ptr_to_ptr)]
2-
2+
#![allow(clippy::transmutes_expressible_as_ptr_casts)]
33
// Make sure we can modify lifetimes, which is one of the recommended uses
44
// of transmute
55

0 commit comments

Comments
 (0)