Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e836a2f
implement continue_ok and break_ok for ControlFlow
jogru0 Apr 24, 2025
b981b84
moved simple test to coretests, introduced more fleshed out doctests …
jogru0 Apr 26, 2025
6dbac3f
add nvptx_target_feature
jedbrown Feb 27, 2025
35a485d
target-feature: enable rust target features implied by target-cpu
jedbrown May 22, 2025
4f1c4e2
don't schedule unnecessary drops when lowering or-patterns
dianne Jul 9, 2025
fee2dfd
base drop order on the first sub-branch
dianne Jul 9, 2025
19ce23c
lower bindings in the order they're written
dianne Jul 10, 2025
ec40ee4
Add documentation for unstable_feature_bound
tiif Jul 30, 2025
712c28e
Remove space
tiif Jul 30, 2025
1fe1bf5
explicit tail call tests with indirect operands in LLVM, small test f…
tnuha Aug 3, 2025
23e6be2
Port #[macro_export] to the new attribute parsing infrastructure
Periodic1911 Jul 12, 2025
f6ce4ac
Anonymize binders in tail call sig
compiler-errors Aug 2, 2025
904e2af
Port `#[coroutine]` to the new attribute system
scrabsha Aug 1, 2025
91e606b
Tweak auto trait errors
estebank Feb 28, 2025
e9758d9
Rollup merge of #137831 - estebank:auto-trait-err, r=compiler-errors
tgross35 Aug 6, 2025
6b58436
Rollup merge of #138689 - jedbrown:jed/nvptx-target-feature, r=ZuseZ4
tgross35 Aug 6, 2025
0e468e2
Rollup merge of #140267 - jogru0:control_flow, r=dtolnay
tgross35 Aug 6, 2025
aafba6e
Rollup merge of #143764 - dianne:primary-binding-drop-order, r=Nadrie…
tgross35 Aug 6, 2025
2e28a56
Rollup merge of #143857 - Periodic1911:macro-export, r=jdonszelmann
tgross35 Aug 6, 2025
1962b52
Rollup merge of #144650 - Borgerr:additional-tce-tests, r=WaffleLapkin
tgross35 Aug 6, 2025
07feb36
Rollup merge of #144676 - tiif:dev_guide_unstable_bound, r=BoxyUwU
tgross35 Aug 6, 2025
1d6939d
Rollup merge of #144794 - scrabsha:push-noqrrttovmwy, r=jdonszelmann
tgross35 Aug 6, 2025
b616dfc
Rollup merge of #144835 - compiler-errors:tail-call-sig-binder, r=Waf…
tgross35 Aug 6, 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
5 changes: 5 additions & 0 deletions compiler/rustc_attr_parsing/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ attr_parsing_ill_formed_attribute_input = {$num_suggestions ->
*[other] valid forms for the attribute are {$suggestions}
}

attr_parsing_invalid_macro_export_arguments = {$num_suggestions ->
[1] attribute must be of the form {$suggestions}
*[other] valid forms for the attribute are {$suggestions}
}

attr_parsing_incorrect_repr_format_align_one_arg =
incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses

Expand Down
61 changes: 60 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use rustc_errors::DiagArgValue;
use rustc_feature::{AttributeTemplate, template};
use rustc_hir::attrs::{AttributeKind, MacroUseArgs};
use rustc_hir::lints::AttributeLintKind;
use rustc_span::{Span, Symbol, sym};
use thin_vec::ThinVec;

use crate::attributes::{AcceptMapping, AttributeParser, NoArgsAttributeParser, OnDuplicate};
use crate::attributes::{
AcceptMapping, AttributeOrder, AttributeParser, NoArgsAttributeParser, OnDuplicate,
SingleAttributeParser,
};
use crate::context::{AcceptContext, FinalizeContext, Stage};
use crate::parser::ArgParser;
use crate::session_diagnostics;
Expand Down Expand Up @@ -113,3 +117,58 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })
}
}

pub(crate) struct MacroExportParser;

impl<S: Stage> SingleAttributeParser<S> for crate::attributes::macro_attrs::MacroExportParser {
const PATH: &[Symbol] = &[sym::macro_export];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
const TEMPLATE: AttributeTemplate = template!(Word, List: "local_inner_macros");

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
let suggestions =
|| <Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "macro_export");
let local_inner_macros = match args {
ArgParser::NoArgs => false,
ArgParser::List(list) => {
let Some(l) = list.single() else {
let span = cx.attr_span;
cx.emit_lint(
AttributeLintKind::InvalidMacroExportArguments {
suggestions: suggestions(),
},
span,
);
return None;
};
match l.meta_item().and_then(|i| i.path().word_sym()) {
Some(sym::local_inner_macros) => true,
_ => {
let span = cx.attr_span;
cx.emit_lint(
AttributeLintKind::InvalidMacroExportArguments {
suggestions: suggestions(),
},
span,
);
return None;
}
}
}
ArgParser::NameValue(_) => {
let span = cx.attr_span;
let suggestions = suggestions();
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
num_suggestions: suggestions.len(),
suggestions: DiagArgValue::StrListSepByAnd(
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
),
span,
});
return None;
}
};
Some(AttributeKind::MacroExport { span: cx.attr_span, local_inner_macros })
}
}
3 changes: 2 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::attributes::lint_helpers::{
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
};
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser};
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroExportParser, MacroUseParser};
use crate::attributes::must_use::MustUseParser;
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
use crate::attributes::non_exhaustive::NonExhaustiveParser;
Expand Down Expand Up @@ -164,6 +164,7 @@ attribute_parsers!(
Single<LinkNameParser>,
Single<LinkOrdinalParser>,
Single<LinkSectionParser>,
Single<MacroExportParser>,
Single<MustUseParser>,
Single<OptimizeParser>,
Single<PathAttributeParser>,
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_attr_parsing/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,17 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<HirId>, lint_emi
*first_span,
session_diagnostics::EmptyAttributeList { attr_span: *first_span },
),
AttributeLintKind::InvalidMacroExportArguments { suggestions } => lint_emitter
.emit_node_span_lint(
rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS,
*id,
*span,
session_diagnostics::IllFormedAttributeInput {
num_suggestions: suggestions.len(),
suggestions: DiagArgValue::StrListSepByAnd(
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
),
},
),
}
}
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,9 @@ impl SyntaxExtension {
let allow_internal_unsafe =
ast::attr::find_by_name(attrs, sym::allow_internal_unsafe).is_some();

let local_inner_macros = ast::attr::find_by_name(attrs, sym::macro_export)
.and_then(|macro_export| macro_export.meta_item_list())
.is_some_and(|l| ast::attr::list_contains_name(&l, sym::local_inner_macros));
let local_inner_macros =
*find_attr!(attrs, AttributeKind::MacroExport {local_inner_macros: l, ..} => l)
.unwrap_or(&false);
let collapse_debuginfo = Self::get_collapse_debuginfo(sess, attrs, !is_local);
tracing::debug!(?name, ?local_inner_macros, ?collapse_debuginfo, ?allow_internal_unsafe);

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ pub enum AttributeKind {
/// Represents `#[macro_escape]`.
MacroEscape(Span),

/// Represents [`#[macro_export]`](https://doc.rust-lang.org/reference/macros-by-example.html#r-macro.decl.scope.path).
MacroExport { span: Span, local_inner_macros: bool },

/// Represents `#[rustc_macro_transparency]`.
MacroTransparency(Transparency),

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/attrs/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl AttributeKind {
LinkSection { .. } => Yes, // Needed for rustdoc
LoopMatch(..) => No,
MacroEscape(..) => No,
MacroExport { .. } => Yes,
MacroTransparency(..) => Yes,
MacroUse { .. } => No,
Marker(..) => No,
Expand Down
21 changes: 18 additions & 3 deletions compiler/rustc_hir/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ pub struct AttributeLint<Id> {

#[derive(Clone, Debug, HashStable_Generic)]
pub enum AttributeLintKind {
UnusedDuplicate { this: Span, other: Span, warning: bool },
IllFormedAttributeInput { suggestions: Vec<String> },
EmptyAttribute { first_span: Span },
UnusedDuplicate {
this: Span,
other: Span,
warning: bool,
},
IllFormedAttributeInput {
suggestions: Vec<String>,
},
EmptyAttribute {
first_span: Span,
},

/// Copy of `IllFormedAttributeInput`
/// specifically for the `invalid_macro_export_arguments` lint until that is removed,
/// see <https://github.com/rust-lang/rust/pull/143857#issuecomment-3079175663>
InvalidMacroExportArguments {
suggestions: Vec<String>,
},
}
10 changes: 7 additions & 3 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use rustc_errors::MultiSpan;
use rustc_hir::attrs::AttributeKind;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{self, Visitor, VisitorExt};
use rustc_hir::{Body, HirId, Item, ItemKind, Node, Path, TyKind};
use rustc_hir::{Body, HirId, Item, ItemKind, Node, Path, TyKind, find_attr};
use rustc_middle::ty::TyCtxt;
use rustc_session::{declare_lint, impl_lint_pass};
use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_span::{ExpnKind, MacroKind, Span, kw, sym};
use rustc_span::{ExpnKind, MacroKind, Span, kw};

use crate::lints::{NonLocalDefinitionsCargoUpdateNote, NonLocalDefinitionsDiag};
use crate::{LateContext, LateLintPass, LintContext, fluent_generated as fluent};
Expand Down Expand Up @@ -241,7 +242,10 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
)
}
ItemKind::Macro(_, _macro, MacroKind::Bang)
if cx.tcx.has_attr(item.owner_id.def_id, sym::macro_export) =>
if find_attr!(
cx.tcx.get_all_attrs(item.owner_id.def_id),
AttributeKind::MacroExport { .. }
) =>
{
cx.emit_span_lint(
NON_LOCAL_DEFINITIONS,
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4188,8 +4188,13 @@ declare_lint! {
/// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`.
///
pub INVALID_MACRO_EXPORT_ARGUMENTS,
Warn,
Deny,
"\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
report_in_deps: true,
};
}

declare_lint! {
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,6 @@ passes_invalid_attr_at_crate_level =
passes_invalid_attr_at_crate_level_item =
the inner attribute doesn't annotate this {$kind}

passes_invalid_macro_export_arguments = invalid `#[macro_export]` argument

passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments

passes_lang_item_fn = {$name ->
[panic_impl] `#[panic_handler]`
*[other] `{$name}` lang item
Expand Down
40 changes: 13 additions & 27 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ use rustc_middle::{bug, span_bug};
use rustc_session::config::CrateType;
use rustc_session::lint;
use rustc_session::lint::builtin::{
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
MALFORMED_DIAGNOSTIC_ATTRIBUTES, MISPLACED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
USELESS_DEPRECATED,
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, MALFORMED_DIAGNOSTIC_ATTRIBUTES,
MISPLACED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES, USELESS_DEPRECATED,
};
use rustc_session::parse::feature_err;
use rustc_span::edition::Edition;
Expand Down Expand Up @@ -291,6 +290,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::Dummy
| AttributeKind::RustcBuiltinMacro { .. },
) => { /* do nothing */ }
Attribute::Parsed(AttributeKind::MacroExport { span, .. }) => {
self.check_macro_export(hir_id, *span, target)
}
Attribute::Parsed(AttributeKind::AsPtr(attr_span)) => {
self.check_applied_to_fn_or_method(hir_id, *attr_span, span, target)
}
Expand Down Expand Up @@ -383,7 +385,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
[sym::ffi_const, ..] => self.check_ffi_const(attr.span(), target),
[sym::link, ..] => self.check_link(hir_id, attr, span, target),
[sym::path, ..] => self.check_generic_attr_unparsed(hir_id, attr, target, Target::Mod),
[sym::macro_export, ..] => self.check_macro_export(hir_id, attr, target),
[sym::should_panic, ..] => {
self.check_generic_attr_unparsed(hir_id, attr, target, Target::Fn)
}
Expand Down Expand Up @@ -2432,32 +2433,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) {
fn check_macro_export(&self, hir_id: HirId, attr_span: Span, target: Target) {
if target != Target::MacroDef {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span(),
attr_span,
errors::MacroExport::Normal,
);
} else if let Some(meta_item_list) = attr.meta_item_list()
&& !meta_item_list.is_empty()
{
if meta_item_list.len() > 1 {
self.tcx.emit_node_span_lint(
INVALID_MACRO_EXPORT_ARGUMENTS,
hir_id,
attr.span(),
errors::MacroExport::TooManyItems,
);
} else if !meta_item_list[0].has_name(sym::local_inner_macros) {
self.tcx.emit_node_span_lint(
INVALID_MACRO_EXPORT_ARGUMENTS,
hir_id,
meta_item_list[0].span(),
errors::MacroExport::InvalidArgument,
);
}
} else {
// special case when `#[macro_export]` is applied to a macro 2.0
let (_, macro_definition, _) = self.tcx.hir_node(hir_id).expect_item().expect_macro();
Expand All @@ -2467,7 +2450,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span(),
attr_span,
errors::MacroExport::OnDeclMacro,
);
}
Expand Down Expand Up @@ -2820,7 +2803,9 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
// In the long run, the checks should be harmonized.
if let ItemKind::Macro(_, macro_def, _) = item.kind {
let def_id = item.owner_id.to_def_id();
if macro_def.macro_rules && !self.tcx.has_attr(def_id, sym::macro_export) {
if macro_def.macro_rules
&& !find_attr!(self.tcx.get_all_attrs(def_id), AttributeKind::MacroExport { .. })
{
check_non_exported_macro_for_invalid_attrs(self.tcx, item);
}
}
Expand Down Expand Up @@ -2950,7 +2935,6 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
// which were unsuccessfully resolved due to cannot determine
// resolution for the attribute macro error.
const ATTRS_TO_CHECK: &[Symbol] = &[
sym::macro_export,
sym::rustc_main,
sym::derive,
sym::test,
Expand All @@ -2975,6 +2959,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
(*span, sym::path)
} else if let Attribute::Parsed(AttributeKind::AutomaticallyDerived(span)) = attr {
(*span, sym::automatically_derived)
} else if let Attribute::Parsed(AttributeKind::MacroExport { span, .. }) = attr {
(*span, sym::macro_export)
} else {
continue;
};
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,6 @@ pub(crate) enum MacroExport {
#[diag(passes_macro_export_on_decl_macro)]
#[note]
OnDeclMacro,

#[diag(passes_invalid_macro_export_arguments)]
InvalidArgument,

#[diag(passes_invalid_macro_export_arguments_too_many_items)]
TooManyItems,
}

#[derive(Subdiagnostic)]
Expand Down
23 changes: 13 additions & 10 deletions src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::collections::{BTreeMap, VecDeque};
use encode::{bitmap_to_string, write_vlqhex_to_string};
use rustc_ast::join_path_syms;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_hir::attrs::AttributeKind;
use rustc_hir::find_attr;
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::DefId;
use rustc_span::sym;
Expand Down Expand Up @@ -421,16 +423,17 @@ pub(crate) fn build_index(
if fqp.last() != Some(&item.name) {
return None;
}
let path =
if item.ty == ItemType::Macro && tcx.has_attr(defid, sym::macro_export) {
// `#[macro_export]` always exports to the crate root.
tcx.crate_name(defid.krate).to_string()
} else {
if fqp.len() < 2 {
return None;
}
join_path_syms(&fqp[..fqp.len() - 1])
};
let path = if item.ty == ItemType::Macro
&& find_attr!(tcx.get_all_attrs(defid), AttributeKind::MacroExport { .. })
{
// `#[macro_export]` always exports to the crate root.
tcx.crate_name(defid.krate).to_string()
} else {
if fqp.len() < 2 {
return None;
}
join_path_syms(&fqp[..fqp.len() - 1])
};
if path == item.path {
return None;
}
Expand Down
Loading