From 657dadf2cc20d7d48643a300c23388ef026c8c83 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 30 Mar 2024 12:10:47 -0400 Subject: [PATCH] Simplify some cfging --- compiler/rustc_middle/src/ty/context.rs | 12 +++++++----- compiler/rustc_middle/src/ty/sty.rs | 16 ++++------------ 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 df792b87056c..09fae0fdd351 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>>, ) -> 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 dc1ad1da7e1f..30997d1350d9 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)) }