Skip to content

Rollup of 11 pull requests #145365

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 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1437559
Add -Zindirect-branch-cs-prefix (from draft PR)
Darksonn May 7, 2025
5d6ec1e
Add `-Zindirect-branch-cs-prefix` option
ojeda May 7, 2025
24c770b
aarch64: Make `outline-atomics` a known target feature
tgross35 Aug 1, 2025
566cdab
Clarify `value_path_str_with_args`.
nnethercote Aug 1, 2025
b0c36dd
Rename most of the printers.
nnethercote Aug 1, 2025
d76eef4
Simplify multiple things.
nnethercote Aug 1, 2025
070425e
Add aarch64_be-unknown-none-softfloat target
Gelbpunkt Aug 5, 2025
dfd38f0
Add comments to `Printer`.
nnethercote Aug 1, 2025
69bcd79
Move `should_truncate` from trait `Printer` to sub-trait `PrettyPrint…
nnethercote Aug 3, 2025
b8adda6
Rename some `Printer` methods.
nnethercote Aug 3, 2025
42a1042
Rename some `PrettyPrinter` methods.
nnethercote Aug 3, 2025
378dd7c
Add regression test for former ICE involving malformed meta items con…
fmease Aug 11, 2025
2563e4a
[AVR] Changed data_layout
tomtor Aug 11, 2025
db1a64c
simplify stack handling, be completely lazy
lcnr Aug 5, 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
6e5a6e0
Install libgccjit into the compiler's sysroot when the GCC codegen ba…
Kobzol Aug 13, 2025
76bc558
Make sure that we won't accidentally ship libgccjit.so in the dist co…
Kobzol Aug 13, 2025
f40a784
Remove the `libgccjit.so.0` alias and only create the versioned libra…
Kobzol Aug 13, 2025
cd79c71
Correctly handle when there are no unstable items in the documented c…
GuillaumeGomez Aug 13, 2025
dc0707a
Add another example for escaped `#` character in doctest in rustdoc book
GuillaumeGomez Aug 13, 2025
6c96c94
Add missing entry in STAGE0_MISSING_TARGETS
Gelbpunkt Aug 13, 2025
85a464c
Rollup merge of #140740 - ojeda:indirect-branch-cs-prefix, r=davidtwco
GuillaumeGomez Aug 13, 2025
db3a079
Rollup merge of #144761 - tgross35:cfg-outline-atomics, r=davidtwco
GuillaumeGomez Aug 13, 2025
8fa0870
Rollup merge of #144949 - nnethercote:more-Printer-cleanups, r=davidtwco
GuillaumeGomez Aug 13, 2025
bdd4cb2
Rollup merge of #144955 - lcnr:lazily-update-non-parent-goals, r=BoxyUwU
GuillaumeGomez Aug 13, 2025
3c0ff33
Rollup merge of #144962 - Gelbpunkt:aarch64_be-unknown-none-softfloat…
GuillaumeGomez Aug 13, 2025
cbd7484
Rollup merge of #145153 - joshtriplett:macro-kinds-plural, r=petroche…
GuillaumeGomez Aug 13, 2025
62a6abe
Rollup merge of #145241 - tomtor:avr-layout, r=nikic
GuillaumeGomez Aug 13, 2025
93f29b0
Rollup merge of #145250 - fmease:regr-test-for-attr-meta-ice, r=jdons…
GuillaumeGomez Aug 13, 2025
7d7f794
Rollup merge of #145341 - Kobzol:codegen-backend-gcc, r=jieyouxu
GuillaumeGomez Aug 13, 2025
e7300e8
Rollup merge of #145349 - GuillaumeGomez:unstable-items-search, r=lol…
GuillaumeGomez Aug 13, 2025
e4571f6
Rollup merge of #145356 - GuillaumeGomez:doctest-escaped, r=fmease
GuillaumeGomez Aug 13, 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
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
15 changes: 15 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ pub(crate) unsafe fn create_module<'ll>(
target_data_layout = target_data_layout.replace("p8:128:128:128:48", "p8:128:128")
}
}
if llvm_version < (22, 0, 0) {
if sess.target.arch == "avr" {
// LLVM 22.0 updated the default layout on avr: https://github.com/llvm/llvm-project/pull/153010
target_data_layout = target_data_layout.replace("n8:16", "n8")
}
}

// Ensure the data-layout values hardcoded remain the defaults.
{
Expand Down Expand Up @@ -457,6 +463,15 @@ pub(crate) unsafe fn create_module<'ll>(
}
}

if sess.opts.unstable_opts.indirect_branch_cs_prefix {
llvm::add_module_flag_u32(
llmod,
llvm::ModuleFlagMergeBehavior::Override,
"indirect_branch_cs_prefix",
1,
);
}

match (sess.opts.unstable_opts.small_data_threshold, sess.target.small_data_threshold_support())
{
// Set up the small-data optimization limit for architectures that use
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use rustc_middle::bug;
use rustc_middle::ty::print::{PrettyPrinter, PrintError, Printer};
use rustc_middle::ty::{self, GenericArg, GenericArgKind, Ty, TyCtxt};

struct AbsolutePathPrinter<'tcx> {
struct TypeNamePrinter<'tcx> {
tcx: TyCtxt<'tcx>,
path: String,
}

impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
Expand Down Expand Up @@ -75,26 +75,26 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
self.pretty_print_dyn_existential(predicates)
}

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

fn path_qualified(
fn print_path_with_qualified(
&mut self,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<(), PrintError> {
self.pretty_path_qualified(self_ty, trait_ref)
self.pretty_print_path_with_qualified(self_ty, trait_ref)
}

fn path_append_impl(
fn print_path_with_impl(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<(), PrintError> {
self.pretty_path_append_impl(
self.pretty_print_path_with_impl(
|cx| {
print_prefix(cx)?;

Expand All @@ -107,7 +107,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
)
}

fn path_append(
fn print_path_with_simple(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
disambiguated_data: &DisambiguatedDefPathData,
Expand All @@ -119,7 +119,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
Ok(())
}

fn path_generic_args(
fn print_path_with_generic_args(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
args: &[GenericArg<'tcx>],
Expand All @@ -135,7 +135,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
}
}

impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
fn should_print_region(&self, _region: ty::Region<'_>) -> bool {
false
}
Expand All @@ -159,15 +159,15 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
}
}

impl Write for AbsolutePathPrinter<'_> {
impl Write for TypeNamePrinter<'_> {
fn write_str(&mut self, s: &str) -> std::fmt::Result {
self.path.push_str(s);
Ok(())
}
}

pub fn type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> String {
let mut p = AbsolutePathPrinter { tcx, path: String::new() };
let mut p = TypeNamePrinter { tcx, path: String::new() };
p.print_type(ty).unwrap();
p.path
}
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