mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-02 06:28:20 +03:00
Cleanup and added transmute to ugly path list
This commit is contained in:
+5
-6
@@ -3,6 +3,7 @@
|
||||
use rustc::middle::ty::TyS;
|
||||
use rustc::middle::ty::TypeVariants::TyRawPtr;
|
||||
use utils;
|
||||
use utils::TRANSMUTE_PATH;
|
||||
|
||||
/// **What it does:** This lint checks for transmutes to the original type of the object.
|
||||
///
|
||||
@@ -17,7 +18,7 @@
|
||||
"transmutes that have the same to and from types"
|
||||
}
|
||||
|
||||
/// **What it does:*** This lint checks for transmutes between a type T and *T.
|
||||
/// **What it does:*** This lint checks for transmutes between a type `T` and `*T`.
|
||||
///
|
||||
/// **Why is this bad?** It's easy to mistakenly transmute between a type and a pointer to that type.
|
||||
///
|
||||
@@ -44,7 +45,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
|
||||
if let ExprPath(None, _) = path_expr.node {
|
||||
let def_id = cx.tcx.def_map.borrow()[&path_expr.id].def_id();
|
||||
|
||||
if utils::match_def_path(cx, def_id, &["core", "intrinsics", "transmute"]) {
|
||||
if utils::match_def_path(cx, def_id, &TRANSMUTE_PATH) {
|
||||
let from_ty = cx.tcx.expr_ty(&args[0]);
|
||||
let to_ty = cx.tcx.expr_ty(e);
|
||||
|
||||
@@ -81,7 +82,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
|
||||
if let ExprPath(None, _) = path_expr.node {
|
||||
let def_id = cx.tcx.def_map.borrow()[&path_expr.id].def_id();
|
||||
|
||||
if utils::match_def_path(cx, def_id, &["core", "intrinsics", "transmute"]) {
|
||||
if utils::match_def_path(cx, def_id, &TRANSMUTE_PATH) {
|
||||
let from_ty = cx.tcx.expr_ty(&args[0]);
|
||||
let to_ty = cx.tcx.expr_ty(e);
|
||||
|
||||
@@ -89,9 +90,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
|
||||
cx.span_lint(CROSSPOINTER_TRANSMUTE,
|
||||
e.span,
|
||||
&format!("transmute from a type (`{}`) to a pointer to that type (`{}`)", from_ty, to_ty));
|
||||
}
|
||||
|
||||
if is_ptr_to(from_ty, to_ty) {
|
||||
} else if is_ptr_to(from_ty, to_ty) {
|
||||
cx.span_lint(CROSSPOINTER_TRANSMUTE,
|
||||
e.span,
|
||||
&format!("transmute from a type (`{}`) to the type that it points to (`{}`)", from_ty, to_ty));
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
pub const REGEX_NEW_PATH: [&'static str; 3] = ["regex", "Regex", "new"];
|
||||
pub const RESULT_PATH: [&'static str; 3] = ["core", "result", "Result"];
|
||||
pub const STRING_PATH: [&'static str; 3] = ["collections", "string", "String"];
|
||||
pub const TRANSMUTE_PATH: [&'static str; 3] = ["core", "intrinsics", "transmute"];
|
||||
pub const VEC_FROM_ELEM_PATH: [&'static str; 3] = ["std", "vec", "from_elem"];
|
||||
pub const VEC_PATH: [&'static str; 3] = ["collections", "vec", "Vec"];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user