diff options
| author | Michael Wright <mikerite@lavabit.com> | 2020-12-16 06:05:25 +0200 |
|---|---|---|
| committer | Michael Wright <mikerite@lavabit.com> | 2020-12-16 06:05:25 +0200 |
| commit | f732cc5cd6aeb06e07bd478d78fccaa625daa685 (patch) | |
| tree | cb41bbaca102d78c1c38f0ea3857fda0156207be | |
| parent | 64e630c28018972479394a2fbdcc9f7d8856bb91 (diff) | |
| download | rust-f732cc5cd6aeb06e07bd478d78fccaa625daa685.tar.gz rust-f732cc5cd6aeb06e07bd478d78fccaa625daa685.zip | |
Remove unsafe code
| -rw-r--r-- | clippy_lints/src/utils/internal_lints.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 0de87fab528..9ba39f73ee8 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -868,8 +868,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths { #[derive(Default)] pub struct InterningDefinedSymbol { - // Maps the symbol to the constant name. - symbol_map: FxHashMap<String, String>, + // Maps the symbol value to the constant name. + symbol_map: FxHashMap<u32, String>, } impl_lint_pass!(InterningDefinedSymbol => [INTERNING_DEFINED_SYMBOL]); @@ -889,10 +889,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol { if let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id); if let Ok(value) = value.to_u32(); then { - // SAFETY: We're converting the raw bytes of the symbol value back - // into a Symbol instance. - let symbol = unsafe { std::mem::transmute::<u32, Symbol>(value) }; - self.symbol_map.insert(symbol.to_string(), item.ident.to_string()); + self.symbol_map.insert(value, item.ident.to_string()); } } } @@ -905,7 +902,8 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol { if let ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(func).kind(); if match_def_path(cx, *def_id, &paths::SYMBOL_INTERN); if let Some(Constant::Str(arg)) = constant_simple(cx, cx.typeck_results(), arg); - if let Some(symbol_const) = self.symbol_map.get(&arg); + let value = Symbol::intern(&arg).as_u32(); + if let Some(symbol_const) = self.symbol_map.get(&value); then { span_lint_and_sugg( cx, |
