Skip to content
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn expand_preparsed_asm(
if let Some(pos) = snippet.find(needle) {
let end = pos
+ snippet[pos..]
.find(|c| matches!(c, '\n' | ';' | '\\' | '"'))
.find(['\n', ';', '\\', '"'])
.unwrap_or(snippet[pos..].len() - 1);
let inner = InnerSpan::new(pos, end);
return template_sp.from_inner(inner);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) fn expand_assert<'cx>(
segments: cx
.std_path(&[sym::panic, sym::panic_2021])
.into_iter()
.map(|ident| PathSegment::from_ident(ident))
.map(PathSegment::from_ident)
.collect(),
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/assert/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
} else {
format!(
"Assertion failed: {escaped_expr_str}\nWith captures:\n{}",
&self.fmt_string
self.fmt_string
)
}),
suffix: None,
Expand Down
48 changes: 21 additions & 27 deletions compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ mod llvm_enzyme {
let lit = x.lit()?;
match lit.kind {
ast::LitKind::Int(x, _) => Some(x.get()),
_ => return None,
_ => None,
}
}

// Get information about the function the macro is applied to
fn extract_item_info(iitem: &Box<ast::Item>) -> Option<(Visibility, FnSig, Ident, Generics)> {
match &iitem.kind {
ItemKind::Fn(ast::Fn { sig, ident, generics, .. }) => {
Some((iitem.vis.clone(), sig.clone(), ident.clone(), generics.clone()))
Some((iitem.vis.clone(), sig.clone(), *ident, generics.clone()))
}
_ => None,
}
Expand Down Expand Up @@ -115,7 +115,7 @@ mod llvm_enzyme {
let mut activities: Vec<DiffActivity> = vec![];
let mut errors = false;
for x in &meta_item[first_activity..] {
let activity_str = name(&x);
let activity_str = name(x);
let res = DiffActivity::from_str(&activity_str);
match res {
Ok(x) => activities.push(x),
Expand Down Expand Up @@ -158,7 +158,7 @@ mod llvm_enzyme {
let val = first_ident(t);
let t = Token::from_ast_ident(val);
ts.push(TokenTree::Token(t, Spacing::Joint));
ts.push(TokenTree::Token(comma.clone(), Spacing::Alone));
ts.push(TokenTree::Token(comma, Spacing::Alone));
}

pub(crate) fn expand_forward(
Expand Down Expand Up @@ -226,13 +226,9 @@ mod llvm_enzyme {
},
Annotatable::AssocItem(assoc_item, _ctxt @ (Impl { of_trait: _ } | Trait)) => {
match &assoc_item.kind {
ast::AssocItemKind::Fn(ast::Fn { sig, ident, generics, .. }) => Some((
assoc_item.vis.clone(),
sig.clone(),
ident.clone(),
generics.clone(),
true,
)),
ast::AssocItemKind::Fn(ast::Fn { sig, ident, generics, .. }) => {
Some((assoc_item.vis.clone(), sig.clone(), *ident, generics.clone(), true))
}
_ => None,
}
}
Expand All @@ -255,7 +251,7 @@ mod llvm_enzyme {
// create TokenStream from vec elemtents:
// meta_item doesn't have a .tokens field
let mut ts: Vec<TokenTree> = vec![];
if meta_item_vec.len() < 1 {
if meta_item_vec.is_empty() {
// At the bare minimum, we need a fnc name.
dcx.emit_err(diagnostics::AutoDiffMissingConfig { span: item.span() });
return vec![item];
Expand Down Expand Up @@ -294,7 +290,7 @@ mod llvm_enzyme {
let t = Token::new(TokenKind::Literal(l), Span::default());
let comma = Token::new(TokenKind::Comma, Span::default());
ts.push(TokenTree::Token(t, Spacing::Joint));
ts.push(TokenTree::Token(comma.clone(), Spacing::Alone));
ts.push(TokenTree::Token(comma, Spacing::Alone));

for t in meta_item_vec.clone()[start_position..].iter() {
meta_item_inner_to_ts(t, &mut ts);
Expand Down Expand Up @@ -474,7 +470,7 @@ mod llvm_enzyme {
}
};

return vec![orig_annotatable, d_annotatable];
vec![orig_annotatable, d_annotatable]
}

// shadow arguments (the extra ones which were not in the original (primal) function), in reverse mode must be
Expand Down Expand Up @@ -519,10 +515,8 @@ mod llvm_enzyme {
.map(|param| {
let ty = match &param.ty.kind {
TyKind::ImplicitSelf => self_ty(),
TyKind::Ref(lt, mt) if matches!(mt.ty.kind, TyKind::ImplicitSelf) => ecx.ty(
span,
TyKind::Ref(lt.clone(), ast::MutTy { ty: self_ty(), mutbl: mt.mutbl }),
),
TyKind::Ref(lt, mt) if matches!(mt.ty.kind, TyKind::ImplicitSelf) => ecx
.ty(span, TyKind::Ref(*lt, ast::MutTy { ty: self_ty(), mutbl: mt.mutbl })),
TyKind::Ptr(mt) if matches!(mt.ty.kind, TyKind::ImplicitSelf) => {
ecx.ty(span, TyKind::Ptr(ast::MutTy { ty: self_ty(), mutbl: mt.mutbl }))
}
Expand Down Expand Up @@ -603,7 +597,7 @@ mod llvm_enzyme {
let anon_const = AnonConst { id: ast::DUMMY_NODE_ID, value: expr };
Some(AngleBracketedArg::Arg(GenericArg::Const(anon_const)))
}
GenericParamKind::Lifetime { .. } => None,
GenericParamKind::Lifetime => None,
})
.collect::<ThinVec<_>>();

Expand Down Expand Up @@ -722,7 +716,7 @@ mod llvm_enzyme {
for i in 0..x.width {
let mut shadow_arg = arg.clone();
// We += into the shadow in reverse mode.
shadow_arg.ty = Box::new(assure_mut_ref(&arg.ty));
*shadow_arg.ty = assure_mut_ref(&arg.ty);
let old_name = if let PatKind::Ident(_, ident, _) = arg.pat.kind {
ident.name
} else {
Expand All @@ -732,11 +726,11 @@ mod llvm_enzyme {
let name: String = format!("d{}_{}", old_name, i);
new_inputs.push(name.clone());
let ident = Ident::from_str_and_span(&name, shadow_arg.pat.span);
shadow_arg.pat = Box::new(ast::Pat {
*shadow_arg.pat = ast::Pat {
id: ast::DUMMY_NODE_ID,
kind: PatKind::Ident(BindingMode::NONE, ident, None),
span: shadow_arg.pat.span,
});
};
d_inputs.push(shadow_arg.clone());
}
}
Expand All @@ -763,11 +757,11 @@ mod llvm_enzyme {
let name: String = format!("b{}_{}", old_name, i);
new_inputs.push(name.clone());
let ident = Ident::from_str_and_span(&name, shadow_arg.pat.span);
shadow_arg.pat = Box::new(ast::Pat {
*shadow_arg.pat = ast::Pat {
id: ast::DUMMY_NODE_ID,
kind: PatKind::Ident(BindingMode::NONE, ident, None),
span: shadow_arg.pat.span,
});
};
d_inputs.push(shadow_arg.clone());
}
}
Expand All @@ -779,7 +773,7 @@ mod llvm_enzyme {
}
}
if let PatKind::Ident(_, ident, _) = arg.pat.kind {
idents.push(ident.clone());
idents.push(ident);
} else {
panic!("not an ident?");
}
Expand Down Expand Up @@ -891,15 +885,15 @@ mod llvm_enzyme {
if act_ret.len() == 1 {
act_ret[0].clone()
} else {
let kind = TyKind::Tup(act_ret.iter().map(|arg| arg.clone()).collect());
let kind = TyKind::Tup(act_ret);
Box::new(rustc_ast::Ty { kind, id: ast::DUMMY_NODE_ID, span })
}
}
};
d_decl.output = FnRetTy::Ty(ret_ty);
}

let mut d_header = sig.header.clone();
let mut d_header = sig.header;
if unsafe_activities {
d_header.safety = rustc_ast::Safety::Unsafe(span);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/cfg_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub(super) fn expand_cfg_select<'cx>(
) {
Ok(mut branches) => {
if let Some((selected_tts, selected_span)) = branches.pop_first_match(|cfg| {
matches!(attr::eval_config_entry(&ecx.sess, cfg), EvalConfigResult::True)
matches!(attr::eval_config_entry(ecx.sess, cfg), EvalConfigResult::True)
}) {
let mac = CfgSelectResult {
ecx,
Expand Down
41 changes: 16 additions & 25 deletions compiler/rustc_builtin_macros/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,34 @@ impl MultiItemModifier for Expander {
MetaItemKind::List(list) => {
list.iter()
.filter_map(|meta_item_inner| match meta_item_inner {
MetaItemInner::MetaItem(meta) => Some(meta),
MetaItemInner::MetaItem(meta) => {
// Reject `#[derive(Debug = "value", Debug(abc))]`, but recover the
// paths.
report_path_args(sess, meta);
Some(DeriveResolution {
path: meta.path.clone(),
item: dummy_annotatable(),
exts: None,
is_const: self.is_const,
})
}
MetaItemInner::Lit(lit) => {
// Reject `#[derive("Debug")]`.
report_unexpected_meta_item_lit(sess, lit);
None
}
})
.map(|meta| {
// Reject `#[derive(Debug = "value", Debug(abc))]`, but recover the
// paths.
report_path_args(sess, meta);
meta.path.clone()
})
.map(|path| DeriveResolution {
path,
item: dummy_annotatable(),
exts: None,
is_const: self.is_const,
})
.collect()
}
_ => vec![],
};

// Do not configure or clone items unless necessary.
match &mut resolutions[..] {
[] => {}
[first, others @ ..] => {
first.item = cfg_eval(
sess,
features,
item.clone(),
ecx.current_expansion.lint_node_id,
);
for other in others {
other.item = first.item.clone();
}
if let [first, others @ ..] = &mut resolutions {
first.item =
cfg_eval(sess, features, item.clone(), ecx.current_expansion.lint_node_id);
for other in others {
other.item = first.item.clone();
}
}

Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_builtin_macros/src/deriving/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ pub(crate) fn expand_deriving_copy(
path: path_std!(marker::Copy),
skip_path_as_bound: false,
needs_copy_as_bound_if_packed: false,
additional_bounds: Vec::new(),
additional_bounds: SmallVec::new(),
supports_unions: true,
methods: Vec::new(),
associated_types: Vec::new(),
methods: SmallVec::new(),
associated_types: SmallVec::new(),
is_const,
is_staged_api_crate: cx.ecfg.features.staged_api(),
safety: Safety::Default,
document: true,
};
Expand All @@ -44,12 +43,11 @@ pub(crate) fn expand_deriving_const_param_ty(
path: path_std!(marker::ConstParamTy_),
skip_path_as_bound: false,
needs_copy_as_bound_if_packed: false,
additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
additional_bounds: smallvec![ty::Ty::Path(path_std!(cmp::Eq))],
supports_unions: false,
methods: Vec::new(),
associated_types: Vec::new(),
methods: SmallVec::new(),
associated_types: SmallVec::new(),
is_const,
is_staged_api_crate: cx.ecfg.features.staged_api(),
safety: Safety::Default,
document: true,
};
Expand Down
Loading
Loading