Apply not_unsafe_ptr_arg_deref
to type aliases
This commit is contained in:
parent
97a5daa659
commit
875b240083
@ -42,8 +42,7 @@ fn check_raw_ptr<'tcx>(
|
|||||||
let expr = &body.value;
|
let expr = &body.value;
|
||||||
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(def_id) {
|
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(def_id) {
|
||||||
let raw_ptrs = iter_input_pats(decl, body)
|
let raw_ptrs = iter_input_pats(decl, body)
|
||||||
.zip(decl.inputs.iter())
|
.filter_map(|arg| raw_ptr_arg(cx, arg))
|
||||||
.filter_map(|(arg, ty)| raw_ptr_arg(arg, ty))
|
|
||||||
.collect::<HirIdSet>();
|
.collect::<HirIdSet>();
|
||||||
|
|
||||||
if !raw_ptrs.is_empty() {
|
if !raw_ptrs.is_empty() {
|
||||||
@ -59,8 +58,12 @@ fn check_raw_ptr<'tcx>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty<'_>) -> Option<hir::HirId> {
|
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId> {
|
||||||
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.kind, &ty.kind) {
|
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_))) = (
|
||||||
|
&arg.pat.kind,
|
||||||
|
cx.maybe_typeck_results()
|
||||||
|
.map(|typeck_results| typeck_results.pat_ty(arg.pat).kind()),
|
||||||
|
) {
|
||||||
Some(id)
|
Some(id)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -78,6 +78,14 @@ pub fn public(p: *const u8) {
|
|||||||
unsafe { std::ptr::read(p) };
|
unsafe { std::ptr::read(p) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Alias = *const u8;
|
||||||
|
|
||||||
|
pub fn type_alias(p: Alias) {
|
||||||
|
println!("{}", unsafe { *p });
|
||||||
|
println!("{:?}", unsafe { p.as_ref() });
|
||||||
|
unsafe { std::ptr::read(p) };
|
||||||
|
}
|
||||||
|
|
||||||
impl Bar {
|
impl Bar {
|
||||||
fn private(self, p: *const u8) {
|
fn private(self, p: *const u8) {
|
||||||
println!("{}", unsafe { *p });
|
println!("{}", unsafe { *p });
|
||||||
|
@ -69,22 +69,40 @@ LL | unsafe { std::ptr::read(p) };
|
|||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
||||||
--> $DIR/functions.rs:87:34
|
--> $DIR/functions.rs:84:30
|
||||||
|
|
|
||||||
|
LL | println!("{}", unsafe { *p });
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
||||||
|
--> $DIR/functions.rs:85:31
|
||||||
|
|
|
||||||
|
LL | println!("{:?}", unsafe { p.as_ref() });
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
||||||
|
--> $DIR/functions.rs:86:29
|
||||||
|
|
|
||||||
|
LL | unsafe { std::ptr::read(p) };
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
||||||
|
--> $DIR/functions.rs:95:34
|
||||||
|
|
|
|
||||||
LL | println!("{}", unsafe { *p });
|
LL | println!("{}", unsafe { *p });
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
||||||
--> $DIR/functions.rs:88:35
|
--> $DIR/functions.rs:96:35
|
||||||
|
|
|
|
||||||
LL | println!("{:?}", unsafe { p.as_ref() });
|
LL | println!("{:?}", unsafe { p.as_ref() });
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
error: this public function might dereference a raw pointer but is not marked `unsafe`
|
||||||
--> $DIR/functions.rs:89:33
|
--> $DIR/functions.rs:97:33
|
||||||
|
|
|
|
||||||
LL | unsafe { std::ptr::read(p) };
|
LL | unsafe { std::ptr::read(p) };
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: aborting due to 13 previous errors
|
error: aborting due to 16 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user