@@ -339,6 +339,10 @@ impl<'tcx, Tag> Scalar<Tag> {
339339 Scalar :: Raw { data : f. to_bits ( ) , size : 8 }
340340 }
341341
342+ /// This is very rarely the method you want! You should dispatch on the type
343+ /// and use `force_bits`/`assert_bits`/`force_ptr`/`assert_ptr`.
344+ /// This method only exists for the benefit of low-level memory operations
345+ /// as well as the implementation of the `force_*` methods.
342346 #[ inline]
343347 pub fn to_bits_or_ptr (
344348 self ,
@@ -359,6 +363,7 @@ impl<'tcx, Tag> Scalar<Tag> {
359363 }
360364 }
361365
366+ /// Do not call this method! Use either `assert_bits` or `force_bits`.
362367 #[ inline]
363368 pub fn to_bits ( self , target_size : Size ) -> InterpResult < ' tcx , u128 > {
364369 match self {
@@ -372,6 +377,12 @@ impl<'tcx, Tag> Scalar<Tag> {
372377 }
373378 }
374379
380+ #[ inline( always) ]
381+ pub fn assert_bits ( self , target_size : Size ) -> u128 {
382+ self . to_bits ( target_size) . expect ( "Expected Raw bits but got a Pointer" )
383+ }
384+
385+ /// Do not call this method! Use either `assert_ptr` or `force_ptr`.
375386 #[ inline]
376387 pub fn to_ptr ( self ) -> InterpResult < ' tcx , Pointer < Tag > > {
377388 match self {
@@ -381,6 +392,12 @@ impl<'tcx, Tag> Scalar<Tag> {
381392 }
382393 }
383394
395+ #[ inline( always) ]
396+ pub fn assert_ptr ( self ) -> Pointer < Tag > {
397+ self . to_ptr ( ) . expect ( "Expected a Pointer but got Raw bits" )
398+ }
399+
400+ /// Do not call this method! Dispatch based on the type instead.
384401 #[ inline]
385402 pub fn is_bits ( self ) -> bool {
386403 match self {
@@ -389,6 +406,7 @@ impl<'tcx, Tag> Scalar<Tag> {
389406 }
390407 }
391408
409+ /// Do not call this method! Dispatch based on the type instead.
392410 #[ inline]
393411 pub fn is_ptr ( self ) -> bool {
394412 match self {
@@ -536,11 +554,13 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
536554 }
537555 }
538556
557+ /// Do not call this method! Use either `assert_ptr` or `force_ptr`.
539558 #[ inline( always) ]
540559 pub fn to_ptr ( self ) -> InterpResult < ' tcx , Pointer < Tag > > {
541560 self . not_undef ( ) ?. to_ptr ( )
542561 }
543562
563+ /// Do not call this method! Use either `assert_bits` or `force_bits`.
544564 #[ inline( always) ]
545565 pub fn to_bits ( self , target_size : Size ) -> InterpResult < ' tcx , u128 > {
546566 self . not_undef ( ) ?. to_bits ( target_size)
0 commit comments