Add parentheses when necessary in transmute suggestion (fixes #1049)
This commit is contained in:
parent
910a62444c
commit
cdce78a4be
@ -122,7 +122,13 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
|
||||
|
||||
|
||||
let sugg = if from_pty.ty == to_rty.ty {
|
||||
format!("{}{}", deref, arg)
|
||||
// Put things in parentheses if they are more complex
|
||||
match args[0].node {
|
||||
ExprPath(..) | ExprCall(..) | ExprMethodCall(..) | ExprBlock(..) => {
|
||||
format!("{}{}", deref, arg)
|
||||
}
|
||||
_ => format!("{}({})", deref, arg)
|
||||
}
|
||||
} else {
|
||||
format!("{}({} as {} {})", deref, arg, cast, to_rty.ty)
|
||||
};
|
||||
|
@ -58,6 +58,11 @@ unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
|
||||
//~| SUGGESTION = &*m;
|
||||
let _: &T = &*m;
|
||||
|
||||
let _: &mut T = std::mem::transmute(p as *mut T);
|
||||
//~^ ERROR transmute from a pointer type (`*mut T`) to a reference type (`&mut T`)
|
||||
//~| HELP try
|
||||
//~| SUGGESTION = &mut *(p as *mut T);
|
||||
|
||||
let _: &T = std::mem::transmute(o);
|
||||
//~^ ERROR transmute from a pointer type (`*const U`) to a reference type (`&T`)
|
||||
//~| HELP try
|
||||
|
Loading…
Reference in New Issue
Block a user