4 use syntax::codemap::Span;
5 use syntax::parse::token::InternedString;
8 /// **What it does:** This lint checks for imports that remove "unsafe" from an item's name
10 /// **Why is this bad?** Renaming makes it less clear which traits and structures are unsafe.
12 /// **Known problems:** None.
16 /// use std::cell::{UnsafeCell as TotallySafeCell};
18 /// extern crate crossbeam;
19 /// use crossbeam::{spawn_unsafe as spawn};
22 pub UNSAFE_REMOVED_FROM_NAME,
24 "unsafe removed from name"
27 pub struct UnsafeNameRemoval;
29 impl LintPass for UnsafeNameRemoval {
30 fn get_lints(&self) -> LintArray {
31 lint_array!(UNSAFE_REMOVED_FROM_NAME)
35 impl LateLintPass for UnsafeNameRemoval {
36 fn check_item(&mut self, cx: &LateContext, item: &Item) {
37 if let ItemUse(ref item_use) = item.node {
39 ViewPath_::ViewPathSimple(ref name, ref path) => {
43 .expect("use paths cannot be empty")
49 ViewPath_::ViewPathList(_, ref path_list_items) => {
50 for path_list_item in path_list_items.iter() {
51 let plid = path_list_item.node;
52 if let (Some(name), Some(rename)) = (plid.name(), plid.rename()) {
53 unsafe_to_safe_check(name, rename, cx, &item.span);
57 ViewPath_::ViewPathGlob(_) => {}
63 fn unsafe_to_safe_check(old_name: Name, new_name: Name, cx: &LateContext, span: &Span) {
64 let old_str = old_name.as_str();
65 let new_str = new_name.as_str();
66 if contains_unsafe(&old_str) && !contains_unsafe(&new_str) {
69 UNSAFE_REMOVED_FROM_NAME,
72 "removed \"unsafe\" from the name of `{}` in use as `{}`",
79 fn contains_unsafe(name: &InternedString) -> bool {
80 name.contains("Unsafe") || name.contains("unsafe")