3 use syntax::codemap::Span;
4 use syntax::symbol::InternedString;
7 /// **What it does:** Checks for imports that remove "unsafe" from an item's
10 /// **Why is this bad?** Renaming makes it less clear which traits and
11 /// structures are unsafe.
13 /// **Known problems:** None.
17 /// use std::cell::{UnsafeCell as TotallySafeCell};
19 /// extern crate crossbeam;
20 /// use crossbeam::{spawn_unsafe as spawn};
23 pub UNSAFE_REMOVED_FROM_NAME,
25 "`unsafe` removed from API names on import"
28 pub struct UnsafeNameRemoval;
30 impl LintPass for UnsafeNameRemoval {
31 fn get_lints(&self) -> LintArray {
32 lint_array!(UNSAFE_REMOVED_FROM_NAME)
36 impl EarlyLintPass for UnsafeNameRemoval {
37 fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
38 if let ItemKind::Use(ref item_use) = item.node {
40 ViewPath_::ViewPathSimple(ref name, ref path) => {
44 .expect("use paths cannot be empty")
51 ViewPath_::ViewPathList(_, ref path_list_items) => for path_list_item in path_list_items.iter() {
52 let plid = path_list_item.node;
53 if let Some(rename) = plid.rename {
54 unsafe_to_safe_check(plid.name, rename, cx, &item.span);
57 ViewPath_::ViewPathGlob(_) => {},
63 fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext, span: &Span) {
64 let old_str = old_name.name.as_str();
65 let new_str = new_name.name.as_str();
66 if contains_unsafe(&old_str) && !contains_unsafe(&new_str) {
69 UNSAFE_REMOVED_FROM_NAME,
71 &format!("removed \"unsafe\" from the name of `{}` in use as `{}`", old_str, new_str),
76 fn contains_unsafe(name: &InternedString) -> bool {
77 name.contains("Unsafe") || name.contains("unsafe")