Skip to content

Commit f732cc5

Browse files
author
Michael Wright
committed
Remove unsafe code
1 parent 64e630c commit f732cc5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

clippy_lints/src/utils/internal_lints.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
868868

869869
#[derive(Default)]
870870
pub struct InterningDefinedSymbol {
871-
// Maps the symbol to the constant name.
872-
symbol_map: FxHashMap<String, String>,
871+
// Maps the symbol value to the constant name.
872+
symbol_map: FxHashMap<u32, String>,
873873
}
874874

875875
impl_lint_pass!(InterningDefinedSymbol => [INTERNING_DEFINED_SYMBOL]);
@@ -889,10 +889,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
889889
if let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id);
890890
if let Ok(value) = value.to_u32();
891891
then {
892-
// SAFETY: We're converting the raw bytes of the symbol value back
893-
// into a Symbol instance.
894-
let symbol = unsafe { std::mem::transmute::<u32, Symbol>(value) };
895-
self.symbol_map.insert(symbol.to_string(), item.ident.to_string());
892+
self.symbol_map.insert(value, item.ident.to_string());
896893
}
897894
}
898895
}
@@ -905,7 +902,8 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
905902
if let ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(func).kind();
906903
if match_def_path(cx, *def_id, &paths::SYMBOL_INTERN);
907904
if let Some(Constant::Str(arg)) = constant_simple(cx, cx.typeck_results(), arg);
908-
if let Some(symbol_const) = self.symbol_map.get(&arg);
905+
let value = Symbol::intern(&arg).as_u32();
906+
if let Some(symbol_const) = self.symbol_map.get(&value);
909907
then {
910908
span_lint_and_sugg(
911909
cx,

0 commit comments

Comments
 (0)