Skip to content

Commit 657dadf

Browse files
Simplify some cfging
1 parent c9f8529 commit 657dadf

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

compiler/rustc_middle/src/ty/context.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,12 @@ impl<'tcx> TyCtxt<'tcx> {
20162016
true
20172017
}
20182018

2019-
pub fn assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) {
2019+
pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) {
2020+
#[cfg(not(debug_assertions))]
2021+
{
2022+
return;
2023+
}
2024+
20202025
if !self.check_args_compatible(def_id, args) {
20212026
if let DefKind::AssocTy = self.def_kind(def_id)
20222027
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id))
@@ -2040,10 +2045,7 @@ impl<'tcx> TyCtxt<'tcx> {
20402045
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
20412046
) -> GenericArgsRef<'tcx> {
20422047
let args = self.mk_args_from_iter(args.into_iter().map(Into::into));
2043-
#[cfg(debug_assertions)]
2044-
{
2045-
self.assert_args_compatible(_def_id, args);
2046-
}
2048+
self.debug_assert_args_compatible(_def_id, args);
20472049
args
20482050
}
20492051

compiler/rustc_middle/src/ty/sty.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -1624,9 +1624,7 @@ impl<'tcx> Ty<'tcx> {
16241624

16251625
#[inline]
16261626
pub fn new_adt(tcx: TyCtxt<'tcx>, def: AdtDef<'tcx>, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
1627-
if cfg!(debug_assertions) {
1628-
tcx.assert_args_compatible(def.did(), args);
1629-
}
1627+
tcx.debug_assert_args_compatible(def.did(), args);
16301628
Ty::new(tcx, Adt(def, args))
16311629
}
16321630

@@ -1707,9 +1705,7 @@ impl<'tcx> Ty<'tcx> {
17071705
def_id: DefId,
17081706
closure_args: GenericArgsRef<'tcx>,
17091707
) -> Ty<'tcx> {
1710-
if cfg!(debug_assertions) {
1711-
tcx.assert_args_compatible(def_id, closure_args);
1712-
}
1708+
tcx.debug_assert_args_compatible(def_id, closure_args);
17131709
Ty::new(tcx, Closure(def_id, closure_args))
17141710
}
17151711

@@ -1719,9 +1715,7 @@ impl<'tcx> Ty<'tcx> {
17191715
def_id: DefId,
17201716
closure_args: GenericArgsRef<'tcx>,
17211717
) -> Ty<'tcx> {
1722-
if cfg!(debug_assertions) {
1723-
tcx.assert_args_compatible(def_id, closure_args);
1724-
}
1718+
tcx.debug_assert_args_compatible(def_id, closure_args);
17251719
Ty::new(tcx, CoroutineClosure(def_id, closure_args))
17261720
}
17271721

@@ -1731,9 +1725,7 @@ impl<'tcx> Ty<'tcx> {
17311725
def_id: DefId,
17321726
coroutine_args: GenericArgsRef<'tcx>,
17331727
) -> Ty<'tcx> {
1734-
if cfg!(debug_assertions) {
1735-
tcx.assert_args_compatible(def_id, coroutine_args);
1736-
}
1728+
tcx.debug_assert_args_compatible(def_id, coroutine_args);
17371729
Ty::new(tcx, Coroutine(def_id, coroutine_args))
17381730
}
17391731

0 commit comments

Comments
 (0)