Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f37f9f6

Browse files
committed
Auto merge of rust-lang#108464 - compiler-errors:rollup-trl1g70, r=compiler-errors
Rollup of 7 pull requests Successful merges: - rust-lang#105736 (Test that the compiler/library builds with validate-mir) - rust-lang#107291 ([breaking change] Remove a rustdoc back compat warning) - rust-lang#107675 (Implement -Zlink-directives=yes/no) - rust-lang#107848 (Split `x setup` sub-actions to CLI arguments) - rust-lang#107911 (Add check for invalid #[macro_export] arguments) - rust-lang#108229 ([107049] Recognise top level keys in config.toml.example) - rust-lang#108333 (Make object bound candidates sound in the new trait solver) Failed merges: - rust-lang#108337 (hir-analysis: make a helpful note) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 34e6673 + 4723a9a commit f37f9f6

File tree

33 files changed

+627
-65
lines changed

33 files changed

+627
-65
lines changed

compiler/rustc_interface/locales/en-US.ftl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ interface_mixed_bin_crate =
1111
interface_mixed_proc_macro_crate =
1212
cannot mix `proc-macro` crate type with others
1313
14-
interface_proc_macro_doc_without_arg =
15-
Trying to document proc macro crate without passing '--crate-type proc-macro to rustdoc
16-
.warn = The generated documentation may be incorrect
17-
1814
interface_error_writing_dependencies =
1915
error writing dependencies to `{$path}`: {$error}
2016

compiler/rustc_interface/src/errors.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ pub struct MixedBinCrate;
3131
#[diag(interface_mixed_proc_macro_crate)]
3232
pub struct MixedProcMacroCrate;
3333

34-
#[derive(Diagnostic)]
35-
#[diag(interface_proc_macro_doc_without_arg)]
36-
pub struct ProcMacroDocWithoutArg;
37-
3834
#[derive(Diagnostic)]
3935
#[diag(interface_error_writing_dependencies)]
4036
pub struct ErrorWritingDependencies<'a> {

compiler/rustc_interface/src/passes.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -287,28 +287,18 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
287287
sess.emit_warning(errors::ProcMacroCratePanicAbort);
288288
}
289289

290-
// For backwards compatibility, we don't try to run proc macro injection
291-
// if rustdoc is run on a proc macro crate without '--crate-type proc-macro' being
292-
// specified. This should only affect users who manually invoke 'rustdoc', as
293-
// 'cargo doc' will automatically pass the proper '--crate-type' flags.
294-
// However, we do emit a warning, to let such users know that they should
295-
// start passing '--crate-type proc-macro'
296-
if has_proc_macro_decls && sess.opts.actually_rustdoc && !is_proc_macro_crate {
297-
sess.emit_warning(errors::ProcMacroDocWithoutArg);
298-
} else {
299-
krate = sess.time("maybe_create_a_macro_crate", || {
300-
let is_test_crate = sess.opts.test;
301-
rustc_builtin_macros::proc_macro_harness::inject(
302-
sess,
303-
resolver,
304-
krate,
305-
is_proc_macro_crate,
306-
has_proc_macro_decls,
307-
is_test_crate,
308-
sess.diagnostic(),
309-
)
310-
});
311-
}
290+
krate = sess.time("maybe_create_a_macro_crate", || {
291+
let is_test_crate = sess.opts.test;
292+
rustc_builtin_macros::proc_macro_harness::inject(
293+
sess,
294+
resolver,
295+
krate,
296+
is_proc_macro_crate,
297+
has_proc_macro_decls,
298+
is_test_crate,
299+
sess.diagnostic(),
300+
)
301+
});
312302

313303
// Done with macro expansion!
314304

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ fn test_unstable_options_tracking_hash() {
756756
tracked!(instrument_coverage, Some(InstrumentCoverage::All));
757757
tracked!(instrument_mcount, true);
758758
tracked!(instrument_xray, Some(InstrumentXRay::default()));
759+
tracked!(link_directives, false);
759760
tracked!(link_only, true);
760761
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
761762
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,3 +4103,33 @@ declare_lint! {
41034103
};
41044104
report_in_external_macro
41054105
}
4106+
4107+
declare_lint! {
4108+
/// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments.
4109+
///
4110+
/// ### Example
4111+
///
4112+
/// ```rust,compile_fail
4113+
/// #![deny(invalid_macro_export_arguments)]
4114+
///
4115+
/// #[macro_export(invalid_parameter)]
4116+
/// macro_rules! myMacro {
4117+
/// () => {
4118+
/// // [...]
4119+
/// }
4120+
/// }
4121+
///
4122+
/// #[macro_export(too, many, items)]
4123+
/// ```
4124+
///
4125+
/// {{produces}}
4126+
///
4127+
/// ### Explanation
4128+
///
4129+
/// The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`).
4130+
/// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`.
4131+
///
4132+
pub INVALID_MACRO_EXPORT_ARGUMENTS,
4133+
Warn,
4134+
"\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
4135+
}

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ impl<'tcx> Collector<'tcx> {
103103
}
104104

105105
// Process all of the #[link(..)]-style arguments
106-
let sess = &self.tcx.sess;
106+
let sess = self.tcx.sess;
107107
let features = self.tcx.features();
108+
109+
if !sess.opts.unstable_opts.link_directives {
110+
return;
111+
}
112+
108113
for m in self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| a.has_name(sym::link)) {
109114
let Some(items) = m.meta_item_list() else {
110115
continue;

compiler/rustc_passes/locales/en-US.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,7 @@ passes_proc_macro_invalid_abi = proc macro functions may not be `extern "{$abi}"
745745
passes_proc_macro_unsafe = proc macro functions may not be `unsafe`
746746
747747
passes_skipping_const_checks = skipping const checks
748+
749+
passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument
750+
751+
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments

compiler/rustc_passes/src/check_attr.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
2323
use rustc_middle::ty::query::Providers;
2424
use rustc_middle::ty::{ParamEnv, TyCtxt};
2525
use rustc_session::lint::builtin::{
26-
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES,
26+
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
27+
UNUSED_ATTRIBUTES,
2728
};
2829
use rustc_session::parse::feature_err;
2930
use rustc_span::symbol::{kw, sym, Symbol};
@@ -2102,7 +2103,33 @@ impl CheckAttrVisitor<'_> {
21022103

21032104
fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) {
21042105
if target != Target::MacroDef {
2105-
self.tcx.emit_spanned_lint(UNUSED_ATTRIBUTES, hir_id, attr.span, errors::MacroExport);
2106+
self.tcx.emit_spanned_lint(
2107+
UNUSED_ATTRIBUTES,
2108+
hir_id,
2109+
attr.span,
2110+
errors::MacroExport::Normal,
2111+
);
2112+
} else if let Some(meta_item_list) = attr.meta_item_list() &&
2113+
!meta_item_list.is_empty() {
2114+
if meta_item_list.len() > 1 {
2115+
self.tcx.emit_spanned_lint(
2116+
INVALID_MACRO_EXPORT_ARGUMENTS,
2117+
hir_id,
2118+
attr.span,
2119+
errors::MacroExport::TooManyItems,
2120+
);
2121+
} else {
2122+
if meta_item_list[0].name_or_empty() != sym::local_inner_macros {
2123+
self.tcx.emit_spanned_lint(
2124+
INVALID_MACRO_EXPORT_ARGUMENTS,
2125+
hir_id,
2126+
meta_item_list[0].span(),
2127+
errors::MacroExport::UnknownItem {
2128+
name: meta_item_list[0].name_or_empty(),
2129+
},
2130+
);
2131+
}
2132+
}
21062133
}
21072134
}
21082135

compiler/rustc_passes/src/errors.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,16 @@ pub struct MacroUse {
641641
}
642642

643643
#[derive(LintDiagnostic)]
644-
#[diag(passes_macro_export)]
645-
pub struct MacroExport;
644+
pub enum MacroExport {
645+
#[diag(passes_macro_export)]
646+
Normal,
647+
648+
#[diag(passes_invalid_macro_export_arguments)]
649+
UnknownItem { name: Symbol },
650+
651+
#[diag(passes_invalid_macro_export_arguments_too_many_items)]
652+
TooManyItems,
653+
}
646654

647655
#[derive(LintDiagnostic)]
648656
#[diag(passes_plugin_registrar)]

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,8 @@ options! {
14891489
"keep hygiene data after analysis (default: no)"),
14901490
layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
14911491
"seed layout randomization"),
1492+
link_directives: bool = (true, parse_bool, [TRACKED],
1493+
"honor #[link] directives in the compiled crate (default: yes)"),
14921494
link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
14931495
"link native libraries in the linker invocation (default: yes)"),
14941496
link_only: bool = (false, parse_bool, [TRACKED],

0 commit comments

Comments
 (0)