File tree Expand file tree Collapse file tree 4 files changed +22
-4
lines changed Expand file tree Collapse file tree 4 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 1
1
//! Compiler intrinsics.
2
2
//!
3
- //! The corresponding definitions are in `librustc_codegen_llvm /intrinsic.rs`.
4
- //! The corresponding const implementations are in `librustc_mir /interpret/intrinsics.rs`
3
+ //! The corresponding definitions are in `compiler/rustc_codegen_llvm/src /intrinsic.rs`.
4
+ //! The corresponding const implementations are in `compiler/rustc_mir/src /interpret/intrinsics.rs`
5
5
//!
6
6
//! # Const intrinsics
7
7
//!
10
10
//!
11
11
//! In order to make an intrinsic usable at compile-time, one needs to copy the implementation
12
12
//! from https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs to
13
- //! `librustc_mir /interpret/intrinsics.rs` and add a
13
+ //! `compiler/rustc_mir/src /interpret/intrinsics.rs` and add a
14
14
//! `#[rustc_const_unstable(feature = "foo", issue = "01234")]` to the intrinsic.
15
15
//!
16
16
//! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
@@ -733,6 +733,7 @@ extern "rust-intrinsic" {
733
733
/// own, or if it does not enable any significant optimizations.
734
734
///
735
735
/// This intrinsic does not have a stable counterpart.
736
+ #[ rustc_const_unstable( feature = "const_assume" , issue = "76972" ) ]
736
737
pub fn assume ( b : bool ) ;
737
738
738
739
/// Hints to the compiler that branch condition is likely to be true.
Original file line number Diff line number Diff line change 1
1
use core:: any:: TypeId ;
2
+ use core:: intrinsics:: assume;
2
3
3
4
#[ test]
4
5
fn test_typeid_sized_types ( ) {
@@ -20,3 +21,17 @@ fn test_typeid_unsized_types() {
20
21
assert_eq ! ( TypeId :: of:: <Y >( ) , TypeId :: of:: <Y >( ) ) ;
21
22
assert ! ( TypeId :: of:: <X >( ) != TypeId :: of:: <Y >( ) ) ;
22
23
}
24
+
25
+ // Check that `const_assume` feature allow `assume` intrinsic
26
+ // to be used in const contexts.
27
+ #[ test]
28
+ fn test_assume_can_be_in_const_contexts ( ) {
29
+ const unsafe fn foo ( x : usize , y : usize ) -> usize {
30
+ // SAFETY: the entire function is not safe,
31
+ // but it is just an example not used elsewhere.
32
+ unsafe { assume ( y != 0 ) } ;
33
+ x / y
34
+ }
35
+ let rs = unsafe { foo ( 42 , 97 ) } ;
36
+ assert_eq ! ( rs, 0 ) ;
37
+ }
Original file line number Diff line number Diff line change 8
8
#![ feature( bound_cloned) ]
9
9
#![ feature( box_syntax) ]
10
10
#![ feature( cell_update) ]
11
+ #![ feature( const_assume) ]
12
+ #![ feature( core_intrinsics) ]
11
13
#![ feature( core_private_bignum) ]
12
14
#![ feature( core_private_diy_float) ]
13
15
#![ feature( debug_non_exhaustive) ]
Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ pub struct _TypeDescriptor {
175
175
// to be able to catch Rust panics by simply declaring a `struct rust_panic`.
176
176
//
177
177
// When modifying, make sure that the type name string exactly matches
178
- // the one used in src/librustc_codegen_llvm/ intrinsic.rs.
178
+ // the one used in `compiler/rustc_codegen_llvm/src/ intrinsic.rs` .
179
179
const TYPE_NAME : [ u8 ; 11 ] = * b"rust_panic\0 " ;
180
180
181
181
static mut THROW_INFO : _ThrowInfo = _ThrowInfo {
You can’t perform that action at this time.
0 commit comments