Skip to content

Commit 677d4d0

Browse files
committed
session: diagnostic migration lint on more fns
Apply the diagnostic migration lint to more functions on `Session`. Signed-off-by: David Wood <david.wood@huawei.com>
1 parent 7d7cd17 commit 677d4d0

File tree

13 files changed

+122
-37
lines changed

13 files changed

+122
-37
lines changed

compiler/rustc_driver/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,9 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
12051205
///
12061206
/// When `install_ice_hook` is called, this function will be called as the panic
12071207
/// hook.
1208+
// FIXME(translation): need struct diagnostics implemented on `Handler`
1209+
#[allow(rustc::untranslatable_diagnostic)]
1210+
#[allow(rustc::diagnostic_outside_of_impl)]
12081211
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12091212
let fallback_bundle =
12101213
rustc_errors::fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false);

compiler/rustc_error_messages/locales/en-US/interface.ftl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,13 @@ interface_rustc_error_unexpected_annotation =
4141
4242
interface_failed_writing_file =
4343
failed to write file {$path}: {$error}"
44+
45+
interface_unsupported_crate_type_for_target =
46+
dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`
47+
48+
interface_multiple_output_types_adaption =
49+
due to multiple output types requested, the explicitly specified output file name will be adapted for each output type
50+
51+
interface_ignoring_extra_filename = ignoring -C extra-filename flag due to -o flag
52+
53+
interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag

compiler/rustc_error_messages/locales/en-US/monomorphize.ftl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ monomorphize_large_assignments =
2424
2525
monomorphize_requires_lang_item =
2626
requires `{$lang_item}` lang_item
27+
28+
monomorphize_encountered_error_while_instantiating =
29+
the above error was encountered while instantiating `{$formatted_item}`
30+
31+
monomorphize_unknown_cgu_collection_mode =
32+
unknown codegen-item collection mode '{$mode}', falling back to 'lazy' mode

compiler/rustc_error_messages/locales/en-US/session.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ session_crate_name_invalid = crate names cannot start with a `-`, but `{$s}` has
6666
session_crate_name_empty = crate name must not be empty
6767
6868
session_invalid_character_in_create_name = invalid character `{$character}` in crate name: `{$crate_name}`
69+
70+
session_optimization_fuel_exhausted = optimization-fuel-exhausted: {$msg}

compiler/rustc_errors/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ impl Handler {
936936
self.emit_diag_at_span(Diagnostic::new(Bug, msg), span);
937937
}
938938

939+
#[rustc_lint_diagnostics]
939940
pub fn span_note_without_error(
940941
&self,
941942
span: impl Into<MultiSpan>,
@@ -944,6 +945,7 @@ impl Handler {
944945
self.emit_diag_at_span(Diagnostic::new(Note, msg), span);
945946
}
946947

948+
#[rustc_lint_diagnostics]
947949
pub fn span_note_diag(
948950
&self,
949951
span: Span,
@@ -955,19 +957,23 @@ impl Handler {
955957
}
956958

957959
// NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread
960+
#[rustc_lint_diagnostics]
958961
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> FatalError {
959962
self.inner.borrow_mut().fatal(msg)
960963
}
961964

965+
#[rustc_lint_diagnostics]
962966
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
963967
self.inner.borrow_mut().err(msg)
964968
}
965969

970+
#[rustc_lint_diagnostics]
966971
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
967972
let mut db = DiagnosticBuilder::new(self, Warning(None), msg);
968973
db.emit();
969974
}
970975

976+
#[rustc_lint_diagnostics]
971977
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>) {
972978
DiagnosticBuilder::new(self, Note, msg).emit();
973979
}

compiler/rustc_interface/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rustc_plugin_impl = { path = "../rustc_plugin_impl" }
4545
rustc_privacy = { path = "../rustc_privacy" }
4646
rustc_query_impl = { path = "../rustc_query_impl" }
4747
rustc_resolve = { path = "../rustc_resolve" }
48+
rustc_target = { path = "../rustc_target" }
4849
rustc_trait_selection = { path = "../rustc_trait_selection" }
4950
rustc_ty_utils = { path = "../rustc_ty_utils" }
5051

@@ -54,9 +55,6 @@ libc = "0.2"
5455
[target.'cfg(windows)'.dependencies]
5556
winapi = { version = "0.3", features = ["libloaderapi"] }
5657

57-
[dev-dependencies]
58-
rustc_target = { path = "../rustc_target" }
59-
6058
[features]
6159
llvm = ['rustc_codegen_llvm']
6260
rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler']

compiler/rustc_interface/src/errors.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rustc_macros::SessionDiagnostic;
2+
use rustc_session::config::CrateType;
23
use rustc_span::{Span, Symbol};
4+
use rustc_target::spec::TargetTriple;
35

46
use std::io;
57
use std::path::Path;
@@ -87,3 +89,22 @@ pub struct FailedWritingFile<'a> {
8789
pub path: &'a Path,
8890
pub error: io::Error,
8991
}
92+
93+
#[derive(SessionDiagnostic)]
94+
#[diag(interface::unsupported_crate_type_for_target)]
95+
pub struct UnsupportedCrateTypeForTarget<'a> {
96+
pub crate_type: CrateType,
97+
pub target_triple: &'a TargetTriple,
98+
}
99+
100+
#[derive(SessionDiagnostic)]
101+
#[diag(interface::multiple_output_types_adaption)]
102+
pub struct MultipleOutputTypesAdaption;
103+
104+
#[derive(SessionDiagnostic)]
105+
#[diag(interface::ignoring_extra_filename)]
106+
pub struct IgnoringExtraFilename;
107+
108+
#[derive(SessionDiagnostic)]
109+
#[diag(interface::ignoring_out_dir)]
110+
pub struct IgnoringOutDir;

compiler/rustc_interface/src/util.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::errors;
12
use info;
23
use libloading::Library;
34
use rustc_ast as ast;
@@ -572,16 +573,15 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<C
572573
}
573574

574575
base.retain(|crate_type| {
575-
let res = !output::invalid_output_for_target(session, *crate_type);
576-
577-
if !res {
578-
session.warn(&format!(
579-
"dropping unsupported crate type `{}` for target `{}`",
580-
*crate_type, session.opts.target_triple
581-
));
576+
if output::invalid_output_for_target(session, *crate_type) {
577+
session.emit_warning(errors::UnsupportedCrateTypeForTarget {
578+
crate_type: *crate_type,
579+
target_triple: &session.opts.target_triple,
580+
});
581+
false
582+
} else {
583+
true
582584
}
583-
584-
res
585585
});
586586

587587
base
@@ -624,19 +624,16 @@ pub fn build_output_filenames(
624624
let unnamed_output_types =
625625
sess.opts.output_types.values().filter(|a| a.is_none()).count();
626626
let ofile = if unnamed_output_types > 1 {
627-
sess.warn(
628-
"due to multiple output types requested, the explicitly specified \
629-
output file name will be adapted for each output type",
630-
);
627+
sess.emit_warning(errors::MultipleOutputTypesAdaption);
631628
None
632629
} else {
633630
if !sess.opts.cg.extra_filename.is_empty() {
634-
sess.warn("ignoring -C extra-filename flag due to -o flag");
631+
sess.emit_warning(errors::IgnoringExtraFilename);
635632
}
636633
Some(out_file.clone())
637634
};
638635
if *odir != None {
639-
sess.warn("ignoring --out-dir flag due to -o flag");
636+
sess.emit_warning(errors::IgnoringOutDir);
640637
}
641638

642639
OutputFilenames::new(

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ use std::iter;
201201
use std::ops::Range;
202202
use std::path::PathBuf;
203203

204-
use crate::errors::{LargeAssignmentsLint, RecursionLimit, RequiresLangItem, TypeLengthLimit};
204+
use crate::errors::{
205+
EncounteredErrorWhileInstantiating, LargeAssignmentsLint, RecursionLimit, RequiresLangItem,
206+
TypeLengthLimit,
207+
};
205208

206209
#[derive(PartialEq)]
207210
pub enum MonoItemCollectionMode {
@@ -524,10 +527,10 @@ fn collect_items_rec<'tcx>(
524527
&& starting_point.node.is_user_defined()
525528
{
526529
let formatted_item = with_no_trimmed_paths!(starting_point.node.to_string());
527-
tcx.sess.span_note_without_error(
528-
starting_point.span,
529-
&format!("the above error was encountered while instantiating `{}`", formatted_item),
530-
);
530+
tcx.sess.emit_note(EncounteredErrorWhileInstantiating {
531+
span: starting_point.span,
532+
formatted_item,
533+
});
531534
}
532535
inlining_map.lock_mut().record_accesses(starting_point.node, &neighbors.items);
533536

compiler/rustc_monomorphize/src/errors.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,17 @@ pub struct SymbolAlreadyDefined {
8383
pub span: Option<Span>,
8484
pub symbol: String,
8585
}
86+
87+
#[derive(SessionDiagnostic)]
88+
#[diag(monomorphize::encountered_error_while_instantiating)]
89+
pub struct EncounteredErrorWhileInstantiating {
90+
#[primary_span]
91+
pub span: Span,
92+
pub formatted_item: String,
93+
}
94+
95+
#[derive(SessionDiagnostic)]
96+
#[diag(monomorphize::unknown_cgu_collection_mode)]
97+
pub struct UnknownCguCollectionMode<'a> {
98+
pub mode: &'a str,
99+
}

0 commit comments

Comments
 (0)