Skip to content

Commit 3672a55

Browse files
committed
Auto merge of #145366 - GuillaumeGomez:rollup-v0a6v3u, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - #144761 (aarch64: Make `outline-atomics` a known target feature) - #144949 (More `Printer` cleanups) - #144955 (search graph: lazily update parent goals) - #144962 (Add aarch64_be-unknown-none-softfloat target) - #145153 (Handle macros with multiple kinds, and improve errors) - #145241 ([AVR] Changed data_layout) - #145341 (Install libgccjit into the compiler's sysroot when cg_gcc is enabled) - #145349 (Correctly handle when there are no unstable items in the documented crate) - #145356 (Add another example for escaped `#` character in doctest in rustdoc book) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f5b8a11 + bb46a20 commit 3672a55

File tree

61 files changed

+941
-503
lines changed

Some content is hidden

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

61 files changed

+941
-503
lines changed

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_codegen_llvm/src/context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ pub(crate) unsafe fn create_module<'ll>(
213213
target_data_layout = target_data_layout.replace("p8:128:128:128:48", "p8:128:128")
214214
}
215215
}
216+
if llvm_version < (22, 0, 0) {
217+
if sess.target.arch == "avr" {
218+
// LLVM 22.0 updated the default layout on avr: https://github.com/llvm/llvm-project/pull/153010
219+
target_data_layout = target_data_layout.replace("n8:16", "n8")
220+
}
221+
}
216222

217223
// Ensure the data-layout values hardcoded remain the defaults.
218224
{

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use rustc_middle::bug;
77
use rustc_middle::ty::print::{PrettyPrinter, PrintError, Printer};
88
use rustc_middle::ty::{self, GenericArg, GenericArgKind, Ty, TyCtxt};
99

10-
struct AbsolutePathPrinter<'tcx> {
10+
struct TypeNamePrinter<'tcx> {
1111
tcx: TyCtxt<'tcx>,
1212
path: String,
1313
}
1414

15-
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
15+
impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
1616
fn tcx(&self) -> TyCtxt<'tcx> {
1717
self.tcx
1818
}
@@ -75,26 +75,26 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
7575
self.pretty_print_dyn_existential(predicates)
7676
}
7777

78-
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
78+
fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
7979
self.path.push_str(self.tcx.crate_name(cnum).as_str());
8080
Ok(())
8181
}
8282

83-
fn path_qualified(
83+
fn print_path_with_qualified(
8484
&mut self,
8585
self_ty: Ty<'tcx>,
8686
trait_ref: Option<ty::TraitRef<'tcx>>,
8787
) -> Result<(), PrintError> {
88-
self.pretty_path_qualified(self_ty, trait_ref)
88+
self.pretty_print_path_with_qualified(self_ty, trait_ref)
8989
}
9090

91-
fn path_append_impl(
91+
fn print_path_with_impl(
9292
&mut self,
9393
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
9494
self_ty: Ty<'tcx>,
9595
trait_ref: Option<ty::TraitRef<'tcx>>,
9696
) -> Result<(), PrintError> {
97-
self.pretty_path_append_impl(
97+
self.pretty_print_path_with_impl(
9898
|cx| {
9999
print_prefix(cx)?;
100100

@@ -107,7 +107,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
107107
)
108108
}
109109

110-
fn path_append(
110+
fn print_path_with_simple(
111111
&mut self,
112112
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
113113
disambiguated_data: &DisambiguatedDefPathData,
@@ -119,7 +119,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
119119
Ok(())
120120
}
121121

122-
fn path_generic_args(
122+
fn print_path_with_generic_args(
123123
&mut self,
124124
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
125125
args: &[GenericArg<'tcx>],
@@ -135,7 +135,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
135135
}
136136
}
137137

138-
impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
138+
impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
139139
fn should_print_region(&self, _region: ty::Region<'_>) -> bool {
140140
false
141141
}
@@ -159,15 +159,15 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
159159
}
160160
}
161161

162-
impl Write for AbsolutePathPrinter<'_> {
162+
impl Write for TypeNamePrinter<'_> {
163163
fn write_str(&mut self, s: &str) -> std::fmt::Result {
164164
self.path.push_str(s);
165165
Ok(())
166166
}
167167
}
168168

169169
pub fn type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> String {
170-
let mut p = AbsolutePathPrinter { tcx, path: String::new() };
170+
let mut p = TypeNamePrinter { tcx, path: String::new() };
171171
p.print_type(ty).unwrap();
172172
p.path
173173
}

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

compiler/rustc_expand/src/mbe/macro_check.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ enum NestedMacroState {
357357
/// The token `macro_rules` was processed.
358358
MacroRules,
359359
/// The tokens `macro_rules!` were processed.
360-
MacroRulesNot,
360+
MacroRulesBang,
361361
/// The tokens `macro_rules!` followed by a name were processed. The name may be either directly
362362
/// an identifier or a meta-variable (that hopefully would be instantiated by an identifier).
363-
MacroRulesNotName,
363+
MacroRulesBangName,
364364
/// The keyword `macro` was processed.
365365
Macro,
366366
/// The keyword `macro` followed by a name was processed.
@@ -408,24 +408,24 @@ fn check_nested_occurrences(
408408
NestedMacroState::MacroRules,
409409
&TokenTree::Token(Token { kind: TokenKind::Bang, .. }),
410410
) => {
411-
state = NestedMacroState::MacroRulesNot;
411+
state = NestedMacroState::MacroRulesBang;
412412
}
413413
(
414-
NestedMacroState::MacroRulesNot,
414+
NestedMacroState::MacroRulesBang,
415415
&TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }),
416416
) => {
417-
state = NestedMacroState::MacroRulesNotName;
417+
state = NestedMacroState::MacroRulesBangName;
418418
}
419-
(NestedMacroState::MacroRulesNot, &TokenTree::MetaVar(..)) => {
420-
state = NestedMacroState::MacroRulesNotName;
419+
(NestedMacroState::MacroRulesBang, &TokenTree::MetaVar(..)) => {
420+
state = NestedMacroState::MacroRulesBangName;
421421
// We check that the meta-variable is correctly used.
422422
check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
423423
}
424-
(NestedMacroState::MacroRulesNotName, TokenTree::Delimited(.., del))
424+
(NestedMacroState::MacroRulesBangName, TokenTree::Delimited(.., del))
425425
| (NestedMacroState::MacroName, TokenTree::Delimited(.., del))
426426
if del.delim == Delimiter::Brace =>
427427
{
428-
let macro_rules = state == NestedMacroState::MacroRulesNotName;
428+
let macro_rules = state == NestedMacroState::MacroRulesBangName;
429429
state = NestedMacroState::Empty;
430430
let rest =
431431
check_nested_macro(psess, node_id, macro_rules, &del.tts, &nested_macros, guar);

0 commit comments

Comments
 (0)