Skip to content

Rollup of 5 pull requests #145483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@ pub(crate) unsafe fn create_module<'ll>(
}
}

if let Some(regparm_count) = sess.opts.unstable_opts.regparm {
llvm::add_module_flag_u32(
llmod,
llvm::ModuleFlagMergeBehavior::Error,
"NumRegisterParameters",
regparm_count,
);
}

if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
if sess.target.arch == "aarch64" {
llvm::add_module_flag_u32(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ expand_invalid_fragment_specifier =
invalid fragment specifier `{$fragment}`
.help = {$help}
expand_macro_args_bad_delim = macro attribute argument matchers require parentheses
expand_macro_args_bad_delim = `{$rule_kw}` rule argument matchers require parentheses
expand_macro_args_bad_delim_sugg = the delimiters should be `(` and `)`
expand_macro_body_stability =
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ pub(crate) struct MacroArgsBadDelim {
pub span: Span,
#[subdiagnostic]
pub sugg: MacroArgsBadDelimSugg,
pub rule_kw: Symbol,
}

#[derive(Subdiagnostic)]
Expand Down
31 changes: 31 additions & 0 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_attr_parsing::{EvalConfigResult, ShouldEmit};
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_errors::PResult;
use rustc_feature::Features;
use rustc_hir::def::MacroKinds;
use rustc_parse::parser::{
AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon, RecoverComma,
token_descr,
Expand Down Expand Up @@ -565,6 +566,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
.map(|DeriveResolution { path, item, exts: _, is_const }| {
// FIXME: Consider using the derive resolutions (`_exts`)
// instead of enqueuing the derives to be resolved again later.
// Note that this can result in duplicate diagnostics.
let expn_id = LocalExpnId::fresh_empty();
derive_invocations.push((
Invocation {
Expand Down Expand Up @@ -922,6 +924,35 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
fragment
}
SyntaxExtensionKind::MacroRules(expander)
if expander.kinds().contains(MacroKinds::DERIVE) =>
{
if is_const {
let guar = self
.cx
.dcx()
.span_err(span, "macro `derive` does not support const derives");
return ExpandResult::Ready(fragment_kind.dummy(span, guar));
}
let body = item.to_tokens();
match expander.expand_derive(self.cx, span, &body) {
Ok(tok_result) => {
let fragment =
self.parse_ast_fragment(tok_result, fragment_kind, &path, span);
if macro_stats {
update_derive_macro_stats(
self.cx,
fragment_kind,
span,
&path,
&fragment,
);
}
fragment
}
Err(guar) => return ExpandResult::Ready(fragment_kind.dummy(span, guar)),
}
}
_ => unreachable!(),
},
InvocationKind::GlobDelegation { item, of_trait } => {
Expand Down
24 changes: 17 additions & 7 deletions compiler/rustc_expand/src/mbe/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ use super::macro_rules::{MacroRule, NoopTracker, parser_from_cx};
use crate::expand::{AstFragmentKind, parse_ast_fragment};
use crate::mbe::macro_parser::ParseResult::*;
use crate::mbe::macro_parser::{MatcherLoc, NamedParseResult, TtParser};
use crate::mbe::macro_rules::{Tracker, try_match_macro, try_match_macro_attr};
use crate::mbe::macro_rules::{
Tracker, try_match_macro, try_match_macro_attr, try_match_macro_derive,
};

pub(super) enum FailedMacro<'a> {
Func,
Attr(&'a TokenStream),
Derive,
}

pub(super) fn failed_to_match_macro(
psess: &ParseSess,
sp: Span,
def_span: Span,
name: Ident,
attr_args: Option<&TokenStream>,
args: FailedMacro<'_>,
body: &TokenStream,
rules: &[MacroRule],
) -> (Span, ErrorGuaranteed) {
Expand All @@ -36,10 +44,12 @@ pub(super) fn failed_to_match_macro(
// diagnostics.
let mut tracker = CollectTrackerAndEmitter::new(psess.dcx(), sp);

let try_success_result = if let Some(attr_args) = attr_args {
try_match_macro_attr(psess, name, attr_args, body, rules, &mut tracker)
} else {
try_match_macro(psess, name, body, rules, &mut tracker)
let try_success_result = match args {
FailedMacro::Func => try_match_macro(psess, name, body, rules, &mut tracker),
FailedMacro::Attr(attr_args) => {
try_match_macro_attr(psess, name, attr_args, body, rules, &mut tracker)
}
FailedMacro::Derive => try_match_macro_derive(psess, name, body, rules, &mut tracker),
};

if try_success_result.is_ok() {
Expand Down Expand Up @@ -90,7 +100,7 @@ pub(super) fn failed_to_match_macro(
}

// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
if attr_args.is_none()
if let FailedMacro::Func = args
&& let Some((body, comma_span)) = body.add_comma()
{
for rule in rules {
Expand Down
Loading
Loading