Skip to content

Commit 4e45960

Browse files
committed
Add a pointer to address cast kind
A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable.
1 parent 2f25078 commit 4e45960

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,11 @@ fn check_rvalue<'tcx>(
125125
Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
126126
check_place(tcx, *place, span, body)
127127
},
128-
Rvalue::Cast(CastKind::Misc, operand, cast_ty) => {
129-
use rustc_middle::ty::cast::CastTy;
130-
let cast_in = CastTy::from_ty(operand.ty(body, tcx)).expect("bad input type for cast");
131-
let cast_out = CastTy::from_ty(*cast_ty).expect("bad output type for cast");
132-
match (cast_in, cast_out) {
133-
(CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => {
134-
Err((span, "casting pointers to ints is unstable in const fn".into()))
135-
},
136-
_ => check_operand(tcx, operand, span, body),
137-
}
128+
Rvalue::Cast(CastKind::PointerAddress, _, _) => {
129+
Err((span, "casting pointers to ints is unstable in const fn".into()))
130+
},
131+
Rvalue::Cast(CastKind::Misc, operand, _) => {
132+
check_operand(tcx, operand, span, body)
138133
},
139134
Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), operand, _) => {
140135
check_operand(tcx, operand, span, body)

0 commit comments

Comments
 (0)