Skip to content

Commit b4ecee9

Browse files
committed
accidentally cause an ICE by putting the TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS handling after the match
The reason I did this in the first place was to try and figure out why I don't see my expected 7 error messages
1 parent 7061b1c commit b4ecee9

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -626,21 +626,25 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
626626
);
627627
}
628628
},
629-
(_, _) if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) => {
630-
span_lint(
631-
cx,
632-
TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
633-
e.span,
634-
&format!(
635-
"transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
636-
from_ty,
637-
to_ty
638-
)
639-
);
640-
},
641-
_ => {
642-
return
643-
},
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+
)
644648
}
645649
}
646650
}

0 commit comments

Comments
 (0)