Skip to content

Commit e0125ac

Browse files
committed
Auto merge of #145319 - jhpratt:rollup-caakzqo, r=jhpratt
Rollup of 7 pull requests Successful merges: - #144642 (editorconfig: don't trim trailing whitespace in tests) - #144955 (search graph: lazily update parent goals) - #145153 (Handle macros with multiple kinds, and improve errors) - #145250 (Add regression test for former ICE involving malformed meta items containing interpolated tokens) - #145269 (Deprecate RUST_TEST_* env variables) - #145289 (chore(ci): upgrade checkout to v5) - #145303 (Docs: Link to payload_as_str() from payload().) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8e62bfd + 0d88b94 commit e0125ac

File tree

45 files changed

+555
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+555
-300
lines changed

.editorconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ root = true
77
[*]
88
end_of_line = lf
99
charset = utf-8
10-
trim_trailing_whitespace = true
1110
insert_final_newline = true
1211

12+
# some tests need trailing whitespace in output snapshots
13+
[!tests/]
14+
trim_trailing_whitespace = true
15+
# for actual source code files of test, we still don't want trailing whitespace
16+
[tests/**.{rs,js}]
17+
trim_trailing_whitespace = true
18+
# these specific source files need to have trailing whitespace.
19+
[tests/ui/{frontmatter/frontmatter-whitespace-3.rs,parser/shebang/shebang-space.rs}]
20+
trim_trailing_whitespace = false
21+
1322
[!src/llvm-project]
1423
indent_style = space
1524
indent_size = 4

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
run_type: ${{ steps.jobs.outputs.run_type }}
5353
steps:
5454
- name: Checkout the source code
55-
uses: actions/checkout@v4
55+
uses: actions/checkout@v5
5656
- name: Test citool
5757
# Only test citool on the auto branch, to reduce latency of the calculate matrix job
5858
# on PR/try builds.
@@ -113,7 +113,7 @@ jobs:
113113
run: git config --global core.autocrlf false
114114

115115
- name: checkout the source code
116-
uses: actions/checkout@v4
116+
uses: actions/checkout@v5
117117
with:
118118
fetch-depth: 2
119119

@@ -313,7 +313,7 @@ jobs:
313313
if: ${{ !cancelled() && contains(fromJSON('["auto", "try"]'), needs.calculate_matrix.outputs.run_type) }}
314314
steps:
315315
- name: checkout the source code
316-
uses: actions/checkout@v4
316+
uses: actions/checkout@v5
317317
with:
318318
fetch-depth: 2
319319
# Calculate the exit status of the whole CI workflow.

.github/workflows/dependencies.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
runs-on: ubuntu-24.04
5252
steps:
5353
- name: checkout the source code
54-
uses: actions/checkout@v4
54+
uses: actions/checkout@v5
5555
with:
5656
submodules: recursive
5757
- name: install the bootstrap toolchain
@@ -101,7 +101,7 @@ jobs:
101101
pull-requests: write
102102
steps:
103103
- name: checkout the source code
104-
uses: actions/checkout@v4
104+
uses: actions/checkout@v5
105105

106106
- name: download Cargo.lock from update job
107107
uses: actions/download-artifact@v4

.github/workflows/ghcr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
# Needed to write to the ghcr.io registry
3030
packages: write
3131
steps:
32-
- uses: actions/checkout@v4
32+
- uses: actions/checkout@v5
3333
with:
3434
persist-credentials: false
3535

.github/workflows/post-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
permissions:
1616
pull-requests: write
1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v5
1919
with:
2020
# Make sure that we have enough commits to find the parent merge commit.
2121
# Since all merges should be through merge commits, fetching two commits

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,6 +3889,7 @@ dependencies = [
38893889
name = "rustc_hir"
38903890
version = "0.0.0"
38913891
dependencies = [
3892+
"bitflags",
38923893
"odht",
38933894
"rustc_abi",
38943895
"rustc_arena",

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
436436
let body = Box::new(self.lower_delim_args(body));
437437
let def_id = self.local_def_id(id);
438438
let def_kind = self.tcx.def_kind(def_id);
439-
let DefKind::Macro(macro_kind) = def_kind else {
439+
let DefKind::Macro(macro_kinds) = def_kind else {
440440
unreachable!(
441441
"expected DefKind::Macro for macro item, found {}",
442442
def_kind.descr(def_id.to_def_id())
443443
);
444444
};
445445
let macro_def = self.arena.alloc(ast::MacroDef { body, macro_rules: *macro_rules });
446-
hir::ItemKind::Macro(ident, macro_def, macro_kind)
446+
hir::ItemKind::Macro(ident, macro_def, macro_kinds)
447447
}
448448
ItemKind::Delegation(box delegation) => {
449449
let delegation_results = self.lower_delegation(delegation, id, false);

compiler/rustc_expand/src/base.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, PResult};
1717
use rustc_feature::Features;
1818
use rustc_hir as hir;
1919
use rustc_hir::attrs::{AttributeKind, CfgEntry, Deprecation};
20+
use rustc_hir::def::MacroKinds;
2021
use rustc_hir::{Stability, find_attr};
2122
use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};
2223
use rustc_parse::MACRO_ARGUMENTS;
@@ -718,6 +719,9 @@ impl MacResult for DummyResult {
718719
/// A syntax extension kind.
719720
#[derive(Clone)]
720721
pub enum SyntaxExtensionKind {
722+
/// A `macro_rules!` macro that can work as any `MacroKind`
723+
MacroRules(Arc<crate::MacroRulesMacroExpander>),
724+
721725
/// A token-based function-like macro.
722726
Bang(
723727
/// An expander with signature TokenStream -> TokenStream.
@@ -772,9 +776,39 @@ pub enum SyntaxExtensionKind {
772776
),
773777

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

784+
impl SyntaxExtensionKind {
785+
/// Returns `Some(expander)` for a macro usable as a `LegacyBang`; otherwise returns `None`
786+
///
787+
/// This includes a `MacroRules` with function-like rules.
788+
pub fn as_legacy_bang(&self) -> Option<&(dyn TTMacroExpander + sync::DynSync + sync::DynSend)> {
789+
match self {
790+
SyntaxExtensionKind::LegacyBang(exp) => Some(exp.as_ref()),
791+
SyntaxExtensionKind::MacroRules(exp) if exp.kinds().contains(MacroKinds::BANG) => {
792+
Some(exp.as_ref())
793+
}
794+
_ => None,
795+
}
796+
}
797+
798+
/// Returns `Some(expander)` for a macro usable as an `Attr`; otherwise returns `None`
799+
///
800+
/// This includes a `MacroRules` with `attr` rules.
801+
pub fn as_attr(&self) -> Option<&(dyn AttrProcMacro + sync::DynSync + sync::DynSend)> {
802+
match self {
803+
SyntaxExtensionKind::Attr(exp) => Some(exp.as_ref()),
804+
SyntaxExtensionKind::MacroRules(exp) if exp.kinds().contains(MacroKinds::ATTR) => {
805+
Some(exp.as_ref())
806+
}
807+
_ => None,
808+
}
809+
}
810+
}
811+
778812
/// A struct representing a macro definition in "lowered" form ready for expansion.
779813
pub struct SyntaxExtension {
780814
/// A syntax extension kind.
@@ -804,18 +838,19 @@ pub struct SyntaxExtension {
804838
}
805839

806840
impl SyntaxExtension {
807-
/// Returns which kind of macro calls this syntax extension.
808-
pub fn macro_kind(&self) -> MacroKind {
841+
/// Returns which kinds of macro call this syntax extension.
842+
pub fn macro_kinds(&self) -> MacroKinds {
809843
match self.kind {
810844
SyntaxExtensionKind::Bang(..)
811845
| SyntaxExtensionKind::LegacyBang(..)
812-
| SyntaxExtensionKind::GlobDelegation(..) => MacroKind::Bang,
846+
| SyntaxExtensionKind::GlobDelegation(..) => MacroKinds::BANG,
813847
SyntaxExtensionKind::Attr(..)
814848
| SyntaxExtensionKind::LegacyAttr(..)
815-
| SyntaxExtensionKind::NonMacroAttr => MacroKind::Attr,
849+
| SyntaxExtensionKind::NonMacroAttr => MacroKinds::ATTR,
816850
SyntaxExtensionKind::Derive(..) | SyntaxExtensionKind::LegacyDerive(..) => {
817-
MacroKind::Derive
851+
MacroKinds::DERIVE
818852
}
853+
SyntaxExtensionKind::MacroRules(ref m) => m.kinds(),
819854
}
820855
}
821856

@@ -1024,11 +1059,12 @@ impl SyntaxExtension {
10241059
parent: LocalExpnId,
10251060
call_site: Span,
10261061
descr: Symbol,
1062+
kind: MacroKind,
10271063
macro_def_id: Option<DefId>,
10281064
parent_module: Option<DefId>,
10291065
) -> ExpnData {
10301066
ExpnData::new(
1031-
ExpnKind::Macro(self.macro_kind(), descr),
1067+
ExpnKind::Macro(kind, descr),
10321068
parent.to_expn_id(),
10331069
call_site,
10341070
self.span,

compiler/rustc_expand/src/expand.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
736736

737737
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
738738
ExpandResult::Ready(match invoc.kind {
739-
InvocationKind::Bang { mac, span } => match ext {
740-
SyntaxExtensionKind::Bang(expander) => {
739+
InvocationKind::Bang { mac, span } => {
740+
if let SyntaxExtensionKind::Bang(expander) = ext {
741741
match expander.expand(self.cx, span, mac.args.tokens.clone()) {
742742
Ok(tok_result) => {
743743
let fragment =
@@ -755,8 +755,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
755755
}
756756
Err(guar) => return ExpandResult::Ready(fragment_kind.dummy(span, guar)),
757757
}
758-
}
759-
SyntaxExtensionKind::LegacyBang(expander) => {
758+
} else if let Some(expander) = ext.as_legacy_bang() {
760759
let tok_result = match expander.expand(self.cx, span, mac.args.tokens.clone()) {
761760
ExpandResult::Ready(tok_result) => tok_result,
762761
ExpandResult::Retry(_) => {
@@ -776,11 +775,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
776775
let guar = self.error_wrong_fragment_kind(fragment_kind, &mac, span);
777776
fragment_kind.dummy(span, guar)
778777
}
778+
} else {
779+
unreachable!();
779780
}
780-
_ => unreachable!(),
781-
},
782-
InvocationKind::Attr { attr, pos, mut item, derives } => match ext {
783-
SyntaxExtensionKind::Attr(expander) => {
781+
}
782+
InvocationKind::Attr { attr, pos, mut item, derives } => {
783+
if let Some(expander) = ext.as_attr() {
784784
self.gate_proc_macro_input(&item);
785785
self.gate_proc_macro_attr_item(span, &item);
786786
let tokens = match &item {
@@ -835,8 +835,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
835835
}
836836
Err(guar) => return ExpandResult::Ready(fragment_kind.dummy(span, guar)),
837837
}
838-
}
839-
SyntaxExtensionKind::LegacyAttr(expander) => {
838+
} else if let SyntaxExtensionKind::LegacyAttr(expander) = ext {
840839
match validate_attr::parse_meta(&self.cx.sess.psess, &attr) {
841840
Ok(meta) => {
842841
let item_clone = macro_stats.then(|| item.clone());
@@ -878,15 +877,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
878877
fragment_kind.expect_from_annotatables(iter::once(item))
879878
}
880879
}
881-
}
882-
SyntaxExtensionKind::NonMacroAttr => {
880+
} else if let SyntaxExtensionKind::NonMacroAttr = ext {
883881
// `-Zmacro-stats` ignores these because they don't do any real expansion.
884882
self.cx.expanded_inert_attrs.mark(&attr);
885883
item.visit_attrs(|attrs| attrs.insert(pos, attr));
886884
fragment_kind.expect_from_annotatables(iter::once(item))
885+
} else {
886+
unreachable!();
887887
}
888-
_ => unreachable!(),
889-
},
888+
}
890889
InvocationKind::Derive { path, item, is_const } => match ext {
891890
SyntaxExtensionKind::Derive(expander)
892891
| SyntaxExtensionKind::LegacyDerive(expander) => {

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,6 @@ pub(super) fn failed_to_match_macro(
5858

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

0 commit comments

Comments
 (0)