Skip to content

Commit

Permalink
Auto merge of rust-lang#108464 - compiler-errors:rollup-trl1g70, r=co…
Browse files Browse the repository at this point in the history
…mpiler-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
  • Loading branch information
bors committed Feb 25, 2023
2 parents 34e6673 + 4723a9a commit f37f9f6
Show file tree
Hide file tree
Showing 33 changed files with 627 additions and 65 deletions.
4 changes: 0 additions & 4 deletions compiler/rustc_interface/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ interface_mixed_bin_crate =
interface_mixed_proc_macro_crate =
cannot mix `proc-macro` crate type with others
interface_proc_macro_doc_without_arg =
Trying to document proc macro crate without passing '--crate-type proc-macro to rustdoc
.warn = The generated documentation may be incorrect
interface_error_writing_dependencies =
error writing dependencies to `{$path}`: {$error}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_interface/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ pub struct MixedBinCrate;
#[diag(interface_mixed_proc_macro_crate)]
pub struct MixedProcMacroCrate;

#[derive(Diagnostic)]
#[diag(interface_proc_macro_doc_without_arg)]
pub struct ProcMacroDocWithoutArg;

#[derive(Diagnostic)]
#[diag(interface_error_writing_dependencies)]
pub struct ErrorWritingDependencies<'a> {
Expand Down
34 changes: 12 additions & 22 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,18 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
sess.emit_warning(errors::ProcMacroCratePanicAbort);
}

// For backwards compatibility, we don't try to run proc macro injection
// if rustdoc is run on a proc macro crate without '--crate-type proc-macro' being
// specified. This should only affect users who manually invoke 'rustdoc', as
// 'cargo doc' will automatically pass the proper '--crate-type' flags.
// However, we do emit a warning, to let such users know that they should
// start passing '--crate-type proc-macro'
if has_proc_macro_decls && sess.opts.actually_rustdoc && !is_proc_macro_crate {
sess.emit_warning(errors::ProcMacroDocWithoutArg);
} else {
krate = sess.time("maybe_create_a_macro_crate", || {
let is_test_crate = sess.opts.test;
rustc_builtin_macros::proc_macro_harness::inject(
sess,
resolver,
krate,
is_proc_macro_crate,
has_proc_macro_decls,
is_test_crate,
sess.diagnostic(),
)
});
}
krate = sess.time("maybe_create_a_macro_crate", || {
let is_test_crate = sess.opts.test;
rustc_builtin_macros::proc_macro_harness::inject(
sess,
resolver,
krate,
is_proc_macro_crate,
has_proc_macro_decls,
is_test_crate,
sess.diagnostic(),
)
});

// Done with macro expansion!

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(instrument_coverage, Some(InstrumentCoverage::All));
tracked!(instrument_mcount, true);
tracked!(instrument_xray, Some(InstrumentXRay::default()));
tracked!(link_directives, false);
tracked!(link_only, true);
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
Expand Down
30 changes: 30 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4103,3 +4103,33 @@ declare_lint! {
};
report_in_external_macro
}

declare_lint! {
/// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(invalid_macro_export_arguments)]
///
/// #[macro_export(invalid_parameter)]
/// macro_rules! myMacro {
/// () => {
/// // [...]
/// }
/// }
///
/// #[macro_export(too, many, items)]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`).
/// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`.
///
pub INVALID_MACRO_EXPORT_ARGUMENTS,
Warn,
"\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
}
7 changes: 6 additions & 1 deletion compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ impl<'tcx> Collector<'tcx> {
}

// Process all of the #[link(..)]-style arguments
let sess = &self.tcx.sess;
let sess = self.tcx.sess;
let features = self.tcx.features();

if !sess.opts.unstable_opts.link_directives {
return;
}

for m in self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| a.has_name(sym::link)) {
let Some(items) = m.meta_item_list() else {
continue;
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,7 @@ passes_proc_macro_invalid_abi = proc macro functions may not be `extern "{$abi}"
passes_proc_macro_unsafe = proc macro functions may not be `unsafe`
passes_skipping_const_checks = skipping const checks
passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments
31 changes: 29 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{ParamEnv, TyCtxt};
use rustc_session::lint::builtin::{
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES,
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
UNUSED_ATTRIBUTES,
};
use rustc_session::parse::feature_err;
use rustc_span::symbol::{kw, sym, Symbol};
Expand Down Expand Up @@ -2102,7 +2103,33 @@ impl CheckAttrVisitor<'_> {

fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) {
if target != Target::MacroDef {
self.tcx.emit_spanned_lint(UNUSED_ATTRIBUTES, hir_id, attr.span, errors::MacroExport);
self.tcx.emit_spanned_lint(
UNUSED_ATTRIBUTES,
hir_id,
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_spanned_lint(
INVALID_MACRO_EXPORT_ARGUMENTS,
hir_id,
attr.span,
errors::MacroExport::TooManyItems,
);
} else {
if meta_item_list[0].name_or_empty() != sym::local_inner_macros {
self.tcx.emit_spanned_lint(
INVALID_MACRO_EXPORT_ARGUMENTS,
hir_id,
meta_item_list[0].span(),
errors::MacroExport::UnknownItem {
name: meta_item_list[0].name_or_empty(),
},
);
}
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,16 @@ pub struct MacroUse {
}

#[derive(LintDiagnostic)]
#[diag(passes_macro_export)]
pub struct MacroExport;
pub enum MacroExport {
#[diag(passes_macro_export)]
Normal,

#[diag(passes_invalid_macro_export_arguments)]
UnknownItem { name: Symbol },

#[diag(passes_invalid_macro_export_arguments_too_many_items)]
TooManyItems,
}

#[derive(LintDiagnostic)]
#[diag(passes_plugin_registrar)]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,8 @@ options! {
"keep hygiene data after analysis (default: no)"),
layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
"seed layout randomization"),
link_directives: bool = (true, parse_bool, [TRACKED],
"honor #[link] directives in the compiled crate (default: yes)"),
link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
"link native libraries in the linker invocation (default: yes)"),
link_only: bool = (false, parse_bool, [TRACKED],
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_trait_selection/src/solve/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<TyCtxt<'tcx>> + Copy + Eq {
requirements: impl IntoIterator<Item = Goal<'tcx, ty::Predicate<'tcx>>>,
) -> QueryResult<'tcx>;

// Consider a clause specifically for a `dyn Trait` self type. This requires
// additionally checking all of the supertraits and object bounds to hold,
// since they're not implied by the well-formedness of the object type.
fn consider_object_bound_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
assumption: ty::Predicate<'tcx>,
) -> QueryResult<'tcx>;

fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
Expand Down Expand Up @@ -455,7 +464,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
for assumption in
elaborate_predicates(tcx, bounds.iter().map(|bound| bound.with_self_ty(tcx, self_ty)))
{
match G::consider_implied_clause(self, goal, assumption.predicate, []) {
match G::consider_object_bound_candidate(self, goal, assumption.predicate) {
Ok(result) => {
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result })
}
Expand Down
45 changes: 45 additions & 0 deletions compiler/rustc_trait_selection/src/solve/project_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,51 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
}
}

fn consider_object_bound_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
assumption: ty::Predicate<'tcx>,
) -> QueryResult<'tcx> {
if let Some(poly_projection_pred) = assumption.to_opt_poly_projection_pred()
&& poly_projection_pred.projection_def_id() == goal.predicate.def_id()
{
ecx.probe(|ecx| {
let assumption_projection_pred =
ecx.instantiate_binder_with_infer(poly_projection_pred);
let mut nested_goals = ecx.eq(
goal.param_env,
goal.predicate.projection_ty,
assumption_projection_pred.projection_ty,
)?;

let tcx = ecx.tcx();
let ty::Dynamic(bounds, _, _) = *goal.predicate.self_ty().kind() else {
bug!("expected object type in `consider_object_bound_candidate`");
};
nested_goals.extend(
structural_traits::predicates_for_object_candidate(
ecx,
goal.param_env,
goal.predicate.projection_ty.trait_ref(tcx),
bounds,
)
.into_iter()
.map(|pred| goal.with(tcx, pred)),
);

let subst_certainty = ecx.evaluate_all(nested_goals)?;

ecx.eq_term_and_make_canonical_response(
goal,
subst_certainty,
assumption_projection_pred.term,
)
})
} else {
Err(NoSolution)
}
}

fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,
Expand Down
40 changes: 40 additions & 0 deletions compiler/rustc_trait_selection/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,46 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
}
}

fn consider_object_bound_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
assumption: ty::Predicate<'tcx>,
) -> QueryResult<'tcx> {
if let Some(poly_trait_pred) = assumption.to_opt_poly_trait_pred()
&& poly_trait_pred.def_id() == goal.predicate.def_id()
{
// FIXME: Constness and polarity
ecx.probe(|ecx| {
let assumption_trait_pred =
ecx.instantiate_binder_with_infer(poly_trait_pred);
let mut nested_goals = ecx.eq(
goal.param_env,
goal.predicate.trait_ref,
assumption_trait_pred.trait_ref,
)?;

let tcx = ecx.tcx();
let ty::Dynamic(bounds, _, _) = *goal.predicate.self_ty().kind() else {
bug!("expected object type in `consider_object_bound_candidate`");
};
nested_goals.extend(
structural_traits::predicates_for_object_candidate(
ecx,
goal.param_env,
goal.predicate.trait_ref,
bounds,
)
.into_iter()
.map(|pred| goal.with(tcx, pred)),
);

ecx.evaluate_all_and_make_canonical_response(nested_goals)
})
} else {
Err(NoSolution)
}
}

fn consider_auto_trait_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
Expand Down
Loading

0 comments on commit f37f9f6

Please sign in to comment.