Skip to content

Commit

Permalink
prevent ice by first checking that macro is applicable (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuseZ4 authored Mar 31, 2024
1 parent 415c714 commit fca0b58
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ pub fn expand(
return vec![item];
}
};
let mut orig_item: P<ast::Item> = item.clone().expect_item();
let primal = orig_item.ident.clone();

// Allow using `#[autodiff(...)]` only on a Fn
let (has_ret, sig, sig_span) = if let Annotatable::Item(item) = &item
&& let ItemKind::Fn(box ast::Fn { sig, .. }) = &item.kind
Expand All @@ -100,6 +97,11 @@ pub fn expand(
ecx.sess.dcx().emit_err(errors::AutoDiffInvalidApplication { span: item.span() });
return vec![item];
};

// Now we know that item is a Item::Fn
let mut orig_item: P<ast::Item> = item.clone().expect_item();
let primal = orig_item.ident.clone();

// create TokenStream from vec elemtents:
// meta_item doesn't have a .tokens field
let comma: Token = Token::new(TokenKind::Comma, Span::default());
Expand Down

0 comments on commit fca0b58

Please sign in to comment.