Skip to content

Commit e2d7d42

Browse files
Vayun BiyaniVayun Biyani
Vayun Biyani
authored and
Vayun Biyani
committed
switch #[cfg(not(llvm_enzyme))] to cfg!(llvm_enzyme)
1 parent cb53e97 commit e2d7d42

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

compiler/rustc_builtin_macros/src/autodiff.rs

+6-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! configs (autodiff enabled or disabled), so we have to add cfg's to each import.
44
//! FIXME(ZuseZ4): Remove this once we have a smarter linter.
55
6-
#[cfg(llvm_enzyme)]
76
mod llvm_enzyme {
87
use std::str::FromStr;
98
use std::string::String;
@@ -130,6 +129,11 @@ mod llvm_enzyme {
130129
meta_item: &ast::MetaItem,
131130
mut item: Annotatable,
132131
) -> Vec<Annotatable> {
132+
133+
if cfg!(not(llvm_enzyme)) {
134+
ecx.sess.dcx().emit_err(errors::AutoDiffSupportNotBuild { span: meta_item.span });
135+
return vec![item];
136+
}
133137
let dcx = ecx.sess.dcx();
134138
// first get the annotable item:
135139
let (sig, is_impl): (FnSig, bool) = match &item {
@@ -801,25 +805,4 @@ mod llvm_enzyme {
801805
}
802806
}
803807

804-
#[cfg(not(llvm_enzyme))]
805-
mod ad_fallback {
806-
use rustc_ast::ast;
807-
use rustc_expand::base::{Annotatable, ExtCtxt};
808-
use rustc_span::Span;
809-
810-
use crate::errors;
811-
pub(crate) fn expand(
812-
ecx: &mut ExtCtxt<'_>,
813-
_expand_span: Span,
814-
meta_item: &ast::MetaItem,
815-
item: Annotatable,
816-
) -> Vec<Annotatable> {
817-
ecx.sess.dcx().emit_err(errors::AutoDiffSupportNotBuild { span: meta_item.span });
818-
return vec![item];
819-
}
820-
}
821-
822-
#[cfg(not(llvm_enzyme))]
823-
pub(crate) use ad_fallback::expand;
824-
#[cfg(llvm_enzyme)]
825-
pub(crate) use llvm_enzyme::expand;
808+
pub(crate) use llvm_enzyme::expand;

compiler/rustc_builtin_macros/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ pub(crate) struct AllocMustStatics {
144144
pub(crate) span: Span,
145145
}
146146

147-
#[cfg(llvm_enzyme)]
148147
pub(crate) use autodiff::*;
149148

150-
#[cfg(llvm_enzyme)]
151149
mod autodiff {
152150
use super::*;
153151
#[derive(Diagnostic)]
@@ -203,9 +201,7 @@ mod autodiff {
203201
}
204202
}
205203

206-
#[cfg(not(llvm_enzyme))]
207204
pub(crate) use ad_fallback::*;
208-
#[cfg(not(llvm_enzyme))]
209205
mod ad_fallback {
210206
use super::*;
211207
#[derive(Diagnostic)]

0 commit comments

Comments
 (0)