Skip to content

Rollup of 7 pull requests #145319

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 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7af87d1
editorconfig: don't trim trailing whitespace in tests
lolbinarycat Jul 29, 2025
378dd7c
Add regression test for former ICE involving malformed meta items con…
fmease Aug 11, 2025
c1a31d8
Deprecate RUST_TEST_* env variables
epage Aug 11, 2025
db1a64c
simplify stack handling, be completely lazy
lcnr Aug 5, 2025
bd44d85
Link to payload_as_str() from payload().
m-ou-se Aug 12, 2025
0d72323
chore(ci): upgrade checkout to v5
rejected-l Aug 12, 2025
0b855bc
Switch to a bitflags `MacroKinds` to support macros with more than on…
joshtriplett Aug 8, 2025
d7b30be
Expand documentation of `GlobDelegation`
joshtriplett Aug 9, 2025
c81fcac
Only suggest changing `#[derive(mymacro)]` to `#[mymacro]` for attrib…
joshtriplett Aug 9, 2025
ba231db
Detect and report macro kind mismatches early, and more precisely
joshtriplett Aug 9, 2025
b74e1cb
mbe: Rename macro parsing state names to use `Bang` instead of `Not`
joshtriplett Aug 9, 2025
33ba4a2
clippy: Update for switch to `MacroKinds`
joshtriplett Aug 9, 2025
e1fc89a
rustdoc: Minimal fixes to compile with `MacroKinds`
joshtriplett Aug 9, 2025
ae0acbb
Rollup merge of #144642 - lolbinarycat:editorconfig-no-run-make, r=lcnr
jhpratt Aug 12, 2025
905d7cd
Rollup merge of #144955 - lcnr:lazily-update-non-parent-goals, r=BoxyUwU
jhpratt Aug 12, 2025
d2e4c4d
Rollup merge of #145153 - joshtriplett:macro-kinds-plural, r=petroche…
jhpratt Aug 12, 2025
3fd7ad1
Rollup merge of #145250 - fmease:regr-test-for-attr-meta-ice, r=jdons…
jhpratt Aug 12, 2025
91a99f2
Rollup merge of #145269 - epage:test-env, r=jhpratt
jhpratt Aug 12, 2025
8095423
Rollup merge of #145289 - rejected-l:master, r=Kobzol
jhpratt Aug 12, 2025
0d88b94
Rollup merge of #145303 - m-ou-se:payload-as-str-doc, r=jhpratt
jhpratt Aug 12, 2025
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
11 changes: 10 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# some tests need trailing whitespace in output snapshots
[!tests/]
trim_trailing_whitespace = true
# for actual source code files of test, we still don't want trailing whitespace
[tests/**.{rs,js}]
trim_trailing_whitespace = true
# these specific source files need to have trailing whitespace.
[tests/ui/{frontmatter/frontmatter-whitespace-3.rs,parser/shebang/shebang-space.rs}]
trim_trailing_whitespace = false

[!src/llvm-project]
indent_style = space
indent_size = 4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run_type: ${{ steps.jobs.outputs.run_type }}
steps:
- name: Checkout the source code
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Test citool
# Only test citool on the auto branch, to reduce latency of the calculate matrix job
# on PR/try builds.
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
run: git config --global core.autocrlf false

- name: checkout the source code
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 2

Expand Down Expand Up @@ -313,7 +313,7 @@ jobs:
if: ${{ !cancelled() && contains(fromJSON('["auto", "try"]'), needs.calculate_matrix.outputs.run_type) }}
steps:
- name: checkout the source code
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 2
# Calculate the exit status of the whole CI workflow.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
runs-on: ubuntu-24.04
steps:
- name: checkout the source code
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
submodules: recursive
- name: install the bootstrap toolchain
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
pull-requests: write
steps:
- name: checkout the source code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: download Cargo.lock from update job
uses: actions/download-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# Needed to write to the ghcr.io registry
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
persist-credentials: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/post-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
# Make sure that we have enough commits to find the parent merge commit.
# Since all merges should be through merge commits, fetching two commits
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3889,6 +3889,7 @@ dependencies = [
name = "rustc_hir"
version = "0.0.0"
dependencies = [
"bitflags",
"odht",
"rustc_abi",
"rustc_arena",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
let body = Box::new(self.lower_delim_args(body));
let def_id = self.local_def_id(id);
let def_kind = self.tcx.def_kind(def_id);
let DefKind::Macro(macro_kind) = def_kind else {
let DefKind::Macro(macro_kinds) = def_kind else {
unreachable!(
"expected DefKind::Macro for macro item, found {}",
def_kind.descr(def_id.to_def_id())
);
};
let macro_def = self.arena.alloc(ast::MacroDef { body, macro_rules: *macro_rules });
hir::ItemKind::Macro(ident, macro_def, macro_kind)
hir::ItemKind::Macro(ident, macro_def, macro_kinds)
}
ItemKind::Delegation(box delegation) => {
let delegation_results = self.lower_delegation(delegation, id, false);
Expand Down
48 changes: 42 additions & 6 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, PResult};
use rustc_feature::Features;
use rustc_hir as hir;
use rustc_hir::attrs::{AttributeKind, CfgEntry, Deprecation};
use rustc_hir::def::MacroKinds;
use rustc_hir::{Stability, find_attr};
use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};
use rustc_parse::MACRO_ARGUMENTS;
Expand Down Expand Up @@ -718,6 +719,9 @@ impl MacResult for DummyResult {
/// A syntax extension kind.
#[derive(Clone)]
pub enum SyntaxExtensionKind {
/// A `macro_rules!` macro that can work as any `MacroKind`
MacroRules(Arc<crate::MacroRulesMacroExpander>),

/// A token-based function-like macro.
Bang(
/// An expander with signature TokenStream -> TokenStream.
Expand Down Expand Up @@ -772,9 +776,39 @@ pub enum SyntaxExtensionKind {
),

/// A glob delegation.
///
/// This is for delegated function implementations, and has nothing to do with glob imports.
GlobDelegation(Arc<dyn GlobDelegationExpander + sync::DynSync + sync::DynSend>),
}

impl SyntaxExtensionKind {
/// Returns `Some(expander)` for a macro usable as a `LegacyBang`; otherwise returns `None`
///
/// This includes a `MacroRules` with function-like rules.
pub fn as_legacy_bang(&self) -> Option<&(dyn TTMacroExpander + sync::DynSync + sync::DynSend)> {
match self {
SyntaxExtensionKind::LegacyBang(exp) => Some(exp.as_ref()),
SyntaxExtensionKind::MacroRules(exp) if exp.kinds().contains(MacroKinds::BANG) => {
Some(exp.as_ref())
}
_ => None,
}
}

/// Returns `Some(expander)` for a macro usable as an `Attr`; otherwise returns `None`
///
/// This includes a `MacroRules` with `attr` rules.
pub fn as_attr(&self) -> Option<&(dyn AttrProcMacro + sync::DynSync + sync::DynSend)> {
match self {
SyntaxExtensionKind::Attr(exp) => Some(exp.as_ref()),
SyntaxExtensionKind::MacroRules(exp) if exp.kinds().contains(MacroKinds::ATTR) => {
Some(exp.as_ref())
}
_ => None,
}
}
}

/// A struct representing a macro definition in "lowered" form ready for expansion.
pub struct SyntaxExtension {
/// A syntax extension kind.
Expand Down Expand Up @@ -804,18 +838,19 @@ pub struct SyntaxExtension {
}

impl SyntaxExtension {
/// Returns which kind of macro calls this syntax extension.
pub fn macro_kind(&self) -> MacroKind {
/// Returns which kinds of macro call this syntax extension.
pub fn macro_kinds(&self) -> MacroKinds {
match self.kind {
SyntaxExtensionKind::Bang(..)
| SyntaxExtensionKind::LegacyBang(..)
| SyntaxExtensionKind::GlobDelegation(..) => MacroKind::Bang,
| SyntaxExtensionKind::GlobDelegation(..) => MacroKinds::BANG,
SyntaxExtensionKind::Attr(..)
| SyntaxExtensionKind::LegacyAttr(..)
| SyntaxExtensionKind::NonMacroAttr => MacroKind::Attr,
| SyntaxExtensionKind::NonMacroAttr => MacroKinds::ATTR,
SyntaxExtensionKind::Derive(..) | SyntaxExtensionKind::LegacyDerive(..) => {
MacroKind::Derive
MacroKinds::DERIVE
}
SyntaxExtensionKind::MacroRules(ref m) => m.kinds(),
}
}

Expand Down Expand Up @@ -1024,11 +1059,12 @@ impl SyntaxExtension {
parent: LocalExpnId,
call_site: Span,
descr: Symbol,
kind: MacroKind,
macro_def_id: Option<DefId>,
parent_module: Option<DefId>,
) -> ExpnData {
ExpnData::new(
ExpnKind::Macro(self.macro_kind(), descr),
ExpnKind::Macro(kind, descr),
parent.to_expn_id(),
call_site,
self.span,
Expand Down
27 changes: 13 additions & 14 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {

let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
ExpandResult::Ready(match invoc.kind {
InvocationKind::Bang { mac, span } => match ext {
SyntaxExtensionKind::Bang(expander) => {
InvocationKind::Bang { mac, span } => {
if let SyntaxExtensionKind::Bang(expander) = ext {
match expander.expand(self.cx, span, mac.args.tokens.clone()) {
Ok(tok_result) => {
let fragment =
Expand All @@ -755,8 +755,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
Err(guar) => return ExpandResult::Ready(fragment_kind.dummy(span, guar)),
}
}
SyntaxExtensionKind::LegacyBang(expander) => {
} else if let Some(expander) = ext.as_legacy_bang() {
let tok_result = match expander.expand(self.cx, span, mac.args.tokens.clone()) {
ExpandResult::Ready(tok_result) => tok_result,
ExpandResult::Retry(_) => {
Expand All @@ -776,11 +775,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let guar = self.error_wrong_fragment_kind(fragment_kind, &mac, span);
fragment_kind.dummy(span, guar)
}
} else {
unreachable!();
}
_ => unreachable!(),
},
InvocationKind::Attr { attr, pos, mut item, derives } => match ext {
SyntaxExtensionKind::Attr(expander) => {
}
InvocationKind::Attr { attr, pos, mut item, derives } => {
if let Some(expander) = ext.as_attr() {
self.gate_proc_macro_input(&item);
self.gate_proc_macro_attr_item(span, &item);
let tokens = match &item {
Expand Down Expand Up @@ -835,8 +835,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
Err(guar) => return ExpandResult::Ready(fragment_kind.dummy(span, guar)),
}
}
SyntaxExtensionKind::LegacyAttr(expander) => {
} else if let SyntaxExtensionKind::LegacyAttr(expander) = ext {
match validate_attr::parse_meta(&self.cx.sess.psess, &attr) {
Ok(meta) => {
let item_clone = macro_stats.then(|| item.clone());
Expand Down Expand Up @@ -878,15 +877,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
fragment_kind.expect_from_annotatables(iter::once(item))
}
}
}
SyntaxExtensionKind::NonMacroAttr => {
} else if let SyntaxExtensionKind::NonMacroAttr = ext {
// `-Zmacro-stats` ignores these because they don't do any real expansion.
self.cx.expanded_inert_attrs.mark(&attr);
item.visit_attrs(|attrs| attrs.insert(pos, attr));
fragment_kind.expect_from_annotatables(iter::once(item))
} else {
unreachable!();
}
_ => unreachable!(),
},
}
InvocationKind::Derive { path, item, is_const } => match ext {
SyntaxExtensionKind::Derive(expander)
| SyntaxExtensionKind::LegacyDerive(expander) => {
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_expand/src/mbe/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ pub(super) fn failed_to_match_macro(

let Some(BestFailure { token, msg: label, remaining_matcher, .. }) = tracker.best_failure
else {
// FIXME: we should report this at macro resolution time, as we do for
// `resolve_macro_cannot_use_as_attr`. We can do that once we track multiple macro kinds for a
// Def.
if attr_args.is_none() && !rules.iter().any(|rule| matches!(rule, MacroRule::Func { .. })) {
let msg = format!("macro has no rules for function-like invocation `{name}!`");
let mut err = psess.dcx().struct_span_err(sp, msg);
if !def_head_span.is_dummy() {
let msg = "this macro has no rules for function-like invocation";
err.span_label(def_head_span, msg);
}
return (sp, err.emit());
}
return (sp, psess.dcx().span_delayed_bug(sp, "failed to match a macro"));
};

Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_expand/src/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ enum NestedMacroState {
/// The token `macro_rules` was processed.
MacroRules,
/// The tokens `macro_rules!` were processed.
MacroRulesNot,
MacroRulesBang,
/// The tokens `macro_rules!` followed by a name were processed. The name may be either directly
/// an identifier or a meta-variable (that hopefully would be instantiated by an identifier).
MacroRulesNotName,
MacroRulesBangName,
/// The keyword `macro` was processed.
Macro,
/// The keyword `macro` followed by a name was processed.
Expand Down Expand Up @@ -408,24 +408,24 @@ fn check_nested_occurrences(
NestedMacroState::MacroRules,
&TokenTree::Token(Token { kind: TokenKind::Bang, .. }),
) => {
state = NestedMacroState::MacroRulesNot;
state = NestedMacroState::MacroRulesBang;
}
(
NestedMacroState::MacroRulesNot,
NestedMacroState::MacroRulesBang,
&TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }),
) => {
state = NestedMacroState::MacroRulesNotName;
state = NestedMacroState::MacroRulesBangName;
}
(NestedMacroState::MacroRulesNot, &TokenTree::MetaVar(..)) => {
state = NestedMacroState::MacroRulesNotName;
(NestedMacroState::MacroRulesBang, &TokenTree::MetaVar(..)) => {
state = NestedMacroState::MacroRulesBangName;
// We check that the meta-variable is correctly used.
check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
}
(NestedMacroState::MacroRulesNotName, TokenTree::Delimited(.., del))
(NestedMacroState::MacroRulesBangName, TokenTree::Delimited(.., del))
| (NestedMacroState::MacroName, TokenTree::Delimited(.., del))
if del.delim == Delimiter::Brace =>
{
let macro_rules = state == NestedMacroState::MacroRulesNotName;
let macro_rules = state == NestedMacroState::MacroRulesBangName;
state = NestedMacroState::Empty;
let rest =
check_nested_macro(psess, node_id, macro_rules, &del.tts, &nested_macros, guar);
Expand Down
Loading
Loading