try putting the can_be_expressed_as_pointer_cast at the top and find that we still get an ICE
This commit is contained in:
parent
34d3a0086c
commit
de05212987
@ -330,6 +330,26 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
|
||||
let from_ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
let to_ty = cx.typeck_results().expr_ty(e);
|
||||
|
||||
if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
|
||||
e.span,
|
||||
&format!(
|
||||
"transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
|
||||
from_ty,
|
||||
to_ty
|
||||
),
|
||||
|diag| {
|
||||
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
||||
let sugg = format!("{} as {}", arg, to_ty);
|
||||
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
|
||||
}
|
||||
}
|
||||
);
|
||||
return
|
||||
}
|
||||
|
||||
match (&from_ty.kind, &to_ty.kind) {
|
||||
_ if from_ty == to_ty => span_lint(
|
||||
cx,
|
||||
@ -626,25 +646,9 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
|
||||
);
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
|
||||
e.span,
|
||||
&format!(
|
||||
"transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
|
||||
from_ty,
|
||||
to_ty
|
||||
),
|
||||
|diag| {
|
||||
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
||||
let sugg = format!("{} as {}", arg, to_ty);
|
||||
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
|
||||
}
|
||||
}
|
||||
)
|
||||
_ => {
|
||||
return;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(clippy::transmutes_expressible_as_ptr_casts)]
|
||||
|
||||
extern crate core;
|
||||
|
||||
use std::mem::transmute as my_transmute;
|
||||
use std::vec::Vec as MyVec;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![warn(clippy::transmute_ptr_to_ptr)]
|
||||
|
||||
#![allow(clippy::transmutes_expressible_as_ptr_casts)]
|
||||
// Make sure we can modify lifetimes, which is one of the recommended uses
|
||||
// of transmute
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user