Skip to content

Commit 1f4086b

Browse files
authored
Rollup merge of #148400 - bjorn3:more_accurate_warning, r=lqd
Better warning message for crate type unsupported by codegen backend Turns out cargo doesn't hard code the "for target" part of the message after all.
2 parents 22b5b3f + 3d03550 commit 1f4086b

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,12 @@ fn print_crate_info(
686686
};
687687
let t_outputs = rustc_interface::util::build_output_filenames(attrs, sess);
688688
let crate_name = passes::get_crate_name(sess, attrs);
689-
let crate_types =
690-
collect_crate_types(sess, &codegen_backend.supported_crate_types(sess), attrs);
689+
let crate_types = collect_crate_types(
690+
sess,
691+
&codegen_backend.supported_crate_types(sess),
692+
codegen_backend.name(),
693+
attrs,
694+
);
691695
for &style in &crate_types {
692696
let fname = rustc_session::output::filename_for_input(
693697
sess, style, crate_name, &t_outputs,

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
929929
let crate_types = collect_crate_types(
930930
sess,
931931
&compiler.codegen_backend.supported_crate_types(sess),
932+
compiler.codegen_backend.name(),
932933
&pre_configured_attrs,
933934
);
934935
let stable_crate_id = StableCrateId::new(

compiler/rustc_session/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ session_unleashed_feature_help_unnamed = skipping check that does not even have
140140
141141
session_unstable_virtual_function_elimination = `-Zvirtual-function-elimination` requires `-Clto`
142142
143+
session_unsupported_crate_type_for_codegen_backend =
144+
dropping unsupported crate type `{$crate_type}` for codegen backend `{$codegen_backend}`
145+
143146
session_unsupported_crate_type_for_target =
144147
dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`
145148

compiler/rustc_session/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ struct BinaryFloatLiteralNotSupported {
371371
span: Span,
372372
}
373373

374+
#[derive(Diagnostic)]
375+
#[diag(session_unsupported_crate_type_for_codegen_backend)]
376+
pub(crate) struct UnsupportedCrateTypeForCodegenBackend {
377+
pub(crate) crate_type: CrateType,
378+
pub(crate) codegen_backend: &'static str,
379+
}
380+
374381
#[derive(Diagnostic)]
375382
#[diag(session_unsupported_crate_type_for_target)]
376383
pub(crate) struct UnsupportedCrateTypeForTarget<'a> {

compiler/rustc_session/src/output.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ pub fn categorize_crate_type(s: Symbol) -> Option<CrateType> {
177177
pub fn collect_crate_types(
178178
session: &Session,
179179
backend_crate_types: &[CrateType],
180+
codegen_backend_name: &'static str,
180181
attrs: &[ast::Attribute],
181182
) -> Vec<CrateType> {
182183
// If we're generating a test executable, then ignore all other output
@@ -223,17 +224,18 @@ pub fn collect_crate_types(
223224
}
224225

225226
base.retain(|crate_type| {
226-
if invalid_output_for_target(session, *crate_type)
227-
|| !backend_crate_types.contains(crate_type)
228-
{
229-
// FIXME provide a better warning for the case where the codegen
230-
// backend doesn't support it once cargo doesn't hard code this
231-
// warning message.
227+
if invalid_output_for_target(session, *crate_type) {
232228
session.dcx().emit_warn(errors::UnsupportedCrateTypeForTarget {
233229
crate_type: *crate_type,
234230
target_triple: &session.opts.target_triple,
235231
});
236232
false
233+
} else if !backend_crate_types.contains(crate_type) {
234+
session.dcx().emit_warn(errors::UnsupportedCrateTypeForCodegenBackend {
235+
crate_type: *crate_type,
236+
codegen_backend: codegen_backend_name,
237+
});
238+
false
237239
} else {
238240
true
239241
}

0 commit comments

Comments
 (0)