about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-03-30 12:10:47 -0400
committerMichael Goulet <michael@errs.io>2024-04-03 11:18:56 -0400
commit657dadf2cc20d7d48643a300c23388ef026c8c83 (patch)
tree627555cbfd67f40a4c671bbeaf46b442ac17d48c
parentc9f852979359779ec1c91b91eb477272308a864f (diff)
downloadrust-657dadf2cc20d7d48643a300c23388ef026c8c83.tar.gz
rust-657dadf2cc20d7d48643a300c23388ef026c8c83.zip
Simplify some cfging
-rw-r--r--compiler/rustc_middle/src/ty/context.rs12
-rw-r--r--compiler/rustc_middle/src/ty/sty.rs16
2 files changed, 11 insertions, 17 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index df792b87056..09fae0fdd35 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -2016,7 +2016,12 @@ impl<'tcx> TyCtxt<'tcx> {
         true
     }
 
-    pub fn assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) {
+    pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) {
+        #[cfg(not(debug_assertions))]
+        {
+            return;
+        }
+
         if !self.check_args_compatible(def_id, args) {
             if let DefKind::AssocTy = self.def_kind(def_id)
                 && let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id))
@@ -2040,10 +2045,7 @@ impl<'tcx> TyCtxt<'tcx> {
         args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
     ) -> GenericArgsRef<'tcx> {
         let args = self.mk_args_from_iter(args.into_iter().map(Into::into));
-        #[cfg(debug_assertions)]
-        {
-            self.assert_args_compatible(_def_id, args);
-        }
+        self.debug_assert_args_compatible(_def_id, args);
         args
     }
 
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index dc1ad1da7e1..30997d1350d 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -1624,9 +1624,7 @@ impl<'tcx> Ty<'tcx> {
 
     #[inline]
     pub fn new_adt(tcx: TyCtxt<'tcx>, def: AdtDef<'tcx>, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
-        if cfg!(debug_assertions) {
-            tcx.assert_args_compatible(def.did(), args);
-        }
+        tcx.debug_assert_args_compatible(def.did(), args);
         Ty::new(tcx, Adt(def, args))
     }
 
@@ -1707,9 +1705,7 @@ impl<'tcx> Ty<'tcx> {
         def_id: DefId,
         closure_args: GenericArgsRef<'tcx>,
     ) -> Ty<'tcx> {
-        if cfg!(debug_assertions) {
-            tcx.assert_args_compatible(def_id, closure_args);
-        }
+        tcx.debug_assert_args_compatible(def_id, closure_args);
         Ty::new(tcx, Closure(def_id, closure_args))
     }
 
@@ -1719,9 +1715,7 @@ impl<'tcx> Ty<'tcx> {
         def_id: DefId,
         closure_args: GenericArgsRef<'tcx>,
     ) -> Ty<'tcx> {
-        if cfg!(debug_assertions) {
-            tcx.assert_args_compatible(def_id, closure_args);
-        }
+        tcx.debug_assert_args_compatible(def_id, closure_args);
         Ty::new(tcx, CoroutineClosure(def_id, closure_args))
     }
 
@@ -1731,9 +1725,7 @@ impl<'tcx> Ty<'tcx> {
         def_id: DefId,
         coroutine_args: GenericArgsRef<'tcx>,
     ) -> Ty<'tcx> {
-        if cfg!(debug_assertions) {
-            tcx.assert_args_compatible(def_id, coroutine_args);
-        }
+        tcx.debug_assert_args_compatible(def_id, coroutine_args);
         Ty::new(tcx, Coroutine(def_id, coroutine_args))
     }