Skip to content

Commit f37f9f6

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

33 files changed

+627
-65
lines changed

compiler/rustc_interface/locales/en-US.ftl

-4
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

-4
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

+12-22
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

+1
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

+30
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

+6-1
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

+4
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

+29-2
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

+10-2
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

+2
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],

compiler/rustc_trait_selection/src/solve/assembly.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<TyCtxt<'tcx>> + Copy + Eq {
9999
requirements: impl IntoIterator<Item = Goal<'tcx, ty::Predicate<'tcx>>>,
100100
) -> QueryResult<'tcx>;
101101

102+
// Consider a clause specifically for a `dyn Trait` self type. This requires
103+
// additionally checking all of the supertraits and object bounds to hold,
104+
// since they're not implied by the well-formedness of the object type.
105+
fn consider_object_bound_candidate(
106+
ecx: &mut EvalCtxt<'_, 'tcx>,
107+
goal: Goal<'tcx, Self>,
108+
assumption: ty::Predicate<'tcx>,
109+
) -> QueryResult<'tcx>;
110+
102111
fn consider_impl_candidate(
103112
ecx: &mut EvalCtxt<'_, 'tcx>,
104113
goal: Goal<'tcx, Self>,
@@ -455,7 +464,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
455464
for assumption in
456465
elaborate_predicates(tcx, bounds.iter().map(|bound| bound.with_self_ty(tcx, self_ty)))
457466
{
458-
match G::consider_implied_clause(self, goal, assumption.predicate, []) {
467+
match G::consider_object_bound_candidate(self, goal, assumption.predicate) {
459468
Ok(result) => {
460469
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result })
461470
}

compiler/rustc_trait_selection/src/solve/project_goals.rs

+45
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,51 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
128128
}
129129
}
130130

131+
fn consider_object_bound_candidate(
132+
ecx: &mut EvalCtxt<'_, 'tcx>,
133+
goal: Goal<'tcx, Self>,
134+
assumption: ty::Predicate<'tcx>,
135+
) -> QueryResult<'tcx> {
136+
if let Some(poly_projection_pred) = assumption.to_opt_poly_projection_pred()
137+
&& poly_projection_pred.projection_def_id() == goal.predicate.def_id()
138+
{
139+
ecx.probe(|ecx| {
140+
let assumption_projection_pred =
141+
ecx.instantiate_binder_with_infer(poly_projection_pred);
142+
let mut nested_goals = ecx.eq(
143+
goal.param_env,
144+
goal.predicate.projection_ty,
145+
assumption_projection_pred.projection_ty,
146+
)?;
147+
148+
let tcx = ecx.tcx();
149+
let ty::Dynamic(bounds, _, _) = *goal.predicate.self_ty().kind() else {
150+
bug!("expected object type in `consider_object_bound_candidate`");
151+
};
152+
nested_goals.extend(
153+
structural_traits::predicates_for_object_candidate(
154+
ecx,
155+
goal.param_env,
156+
goal.predicate.projection_ty.trait_ref(tcx),
157+
bounds,
158+
)
159+
.into_iter()
160+
.map(|pred| goal.with(tcx, pred)),
161+
);
162+
163+
let subst_certainty = ecx.evaluate_all(nested_goals)?;
164+
165+
ecx.eq_term_and_make_canonical_response(
166+
goal,
167+
subst_certainty,
168+
assumption_projection_pred.term,
169+
)
170+
})
171+
} else {
172+
Err(NoSolution)
173+
}
174+
}
175+
131176
fn consider_impl_candidate(
132177
ecx: &mut EvalCtxt<'_, 'tcx>,
133178
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+40
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,46 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
8686
}
8787
}
8888

89+
fn consider_object_bound_candidate(
90+
ecx: &mut EvalCtxt<'_, 'tcx>,
91+
goal: Goal<'tcx, Self>,
92+
assumption: ty::Predicate<'tcx>,
93+
) -> QueryResult<'tcx> {
94+
if let Some(poly_trait_pred) = assumption.to_opt_poly_trait_pred()
95+
&& poly_trait_pred.def_id() == goal.predicate.def_id()
96+
{
97+
// FIXME: Constness and polarity
98+
ecx.probe(|ecx| {
99+
let assumption_trait_pred =
100+
ecx.instantiate_binder_with_infer(poly_trait_pred);
101+
let mut nested_goals = ecx.eq(
102+
goal.param_env,
103+
goal.predicate.trait_ref,
104+
assumption_trait_pred.trait_ref,
105+
)?;
106+
107+
let tcx = ecx.tcx();
108+
let ty::Dynamic(bounds, _, _) = *goal.predicate.self_ty().kind() else {
109+
bug!("expected object type in `consider_object_bound_candidate`");
110+
};
111+
nested_goals.extend(
112+
structural_traits::predicates_for_object_candidate(
113+
ecx,
114+
goal.param_env,
115+
goal.predicate.trait_ref,
116+
bounds,
117+
)
118+
.into_iter()
119+
.map(|pred| goal.with(tcx, pred)),
120+
);
121+
122+
ecx.evaluate_all_and_make_canonical_response(nested_goals)
123+
})
124+
} else {
125+
Err(NoSolution)
126+
}
127+
}
128+
89129
fn consider_auto_trait_candidate(
90130
ecx: &mut EvalCtxt<'_, 'tcx>,
91131
goal: Goal<'tcx, Self>,

0 commit comments

Comments
 (0)