about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis
diff options
context:
space:
mode:
authorCelina G. Val <celinval@amazon.com>2025-01-17 14:49:10 -0800
committerCelina G. Val <celinval@amazon.com>2025-02-03 13:55:15 -0800
commit2bb1464cb6b46d175f92943cb0f9ab534e6cc6eb (patch)
treed40d2600e97c5d55a55f2ab38df73a3ed367037b /compiler/rustc_hir_analysis
parent804cce47d96d7b30f3798b51a1377c6697011c54 (diff)
downloadrust-2bb1464cb6b46d175f92943cb0f9ab534e6cc6eb.tar.gz
rust-2bb1464cb6b46d175f92943cb0f9ab534e6cc6eb.zip
Improve contracts intrisics and remove wrapper function
1. Document the new intrinsics.
2. Make the intrinsics actually check the contract if enabled, and
   remove `contract::check_requires` function.
3. Use panic with no unwind in case contract is using to check for
   safety, we probably don't want to unwind. Following the same
   reasoning as UB checks.
Diffstat (limited to 'compiler/rustc_hir_analysis')
-rw-r--r--compiler/rustc_hir_analysis/src/check/intrinsic.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs
index 6c0cebccefd..e641fb0fb62 100644
--- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs
+++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs
@@ -223,17 +223,15 @@ pub fn check_intrinsic_type(
         };
         (n_tps, 0, 0, inputs, output, hir::Safety::Unsafe)
     } else if intrinsic_name == sym::contract_check_ensures {
-        // contract_check_ensures::<'a, Ret, C>(&'a Ret, C) -> bool
+        // contract_check_ensures::<'a, Ret, C>(&'a Ret, C)
         // where C: impl Fn(&'a Ret) -> bool,
         //
-        // so: two type params, one lifetime param, 0 const params, two inputs, returns boolean
+        // so: two type params, one lifetime param, 0 const params, two inputs, no return
 
         let p = generics.param_at(0, tcx);
         let r = ty::Region::new_early_param(tcx, p.to_early_bound_region_data());
         let ref_ret = Ty::new_imm_ref(tcx, r, param(1));
-        // let br = ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BrAnon };
-        // let ref_ret = Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0));
-        (2, 1, 0, vec![ref_ret, param(2)], tcx.types.bool, hir::Safety::Safe)
+        (2, 1, 0, vec![ref_ret, param(2)], tcx.types.unit, hir::Safety::Safe)
     } else {
         let safety = intrinsic_operation_unsafety(tcx, intrinsic_id);
         let (n_tps, n_cts, inputs, output) = match intrinsic_name {
@@ -628,7 +626,7 @@ pub fn check_intrinsic_type(
             // contract_checks() -> bool
             sym::contract_checks => (0, 0, Vec::new(), tcx.types.bool),
             // contract_check_requires::<C>(C) -> bool, where C: impl Fn() -> bool
-            sym::contract_check_requires => (1, 0, vec![param(0)], tcx.types.bool),
+            sym::contract_check_requires => (1, 0, vec![param(0)], tcx.types.unit),
 
             sym::simd_eq
             | sym::simd_ne