forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraw_assign_to_drop.rs
More file actions
42 lines (32 loc) · 953 Bytes
/
Copy pathraw_assign_to_drop.rs
File metadata and controls
42 lines (32 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#![warn(clippy::raw_assign_to_drop)]
#![allow(clippy::missing_safety_doc)]
use std::cell::UnsafeCell;
pub unsafe fn foo(r: *mut String, i: *mut i32) {
unsafe {
*r = "foo".to_owned();
//~^ raw_assign_to_drop
// no lint on {integer}
*i = 47;
(*r, *r) = ("foo".to_owned(), "bar".to_owned());
//~^ raw_assign_to_drop
//~^^ raw_assign_to_drop
(*r, *i) = ("foo".to_owned(), 47);
//~^ raw_assign_to_drop
let mut x: String = Default::default();
*(&mut x as *mut _) = "Foo".to_owned();
//~^ raw_assign_to_drop
// no lint on `u8`
*x.as_mut_ptr() = b'a';
let mut v: Vec<String> = vec![];
*v.as_mut_ptr() = Default::default();
//~^ raw_assign_to_drop
}
}
pub unsafe fn unsafecell() {
// No lint
let c = UnsafeCell::new(String::new());
unsafe {
*c.get() = String::new();
}
}
fn main() {}