mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Rollup merge of #100753 - LuisCardosoOliveira:translation-migrate-session, r=davidtwco
translations(rustc_session): migrates `rustc_session` to use `SessionDiagnostic` - Pt. 1 ## Description This is the first PR for the migration of the module `rustc_session`. You can follow my progress [here](https://github.com/rust-lang/rust/issues/100717#issuecomment-1220279883). The PR migrates the files `cgu_reuse_tracker` and `parse.rs` to use `SessionDiagnostic `.
This commit is contained in:
commit
24922b7a82
@ -1892,7 +1892,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
|
||||
}
|
||||
});
|
||||
|
||||
sess.cgu_reuse_tracker.check_expected_reuse(sess.diagnostic());
|
||||
sess.cgu_reuse_tracker.check_expected_reuse(sess);
|
||||
|
||||
sess.abort_if_errors();
|
||||
|
||||
|
16
compiler/rustc_error_messages/locales/en-US/session.ftl
Normal file
16
compiler/rustc_error_messages/locales/en-US/session.ftl
Normal file
@ -0,0 +1,16 @@
|
||||
session_incorrect_cgu_reuse_type =
|
||||
CGU-reuse for `{$cgu_user_name}` is `{$actual_reuse}` but should be {$at_least ->
|
||||
[one] {"at least "}
|
||||
*[other] {""}
|
||||
}`{$expected_reuse}`
|
||||
|
||||
session_cgu_not_recorded =
|
||||
CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded`
|
||||
|
||||
session_feature_gate_error = {$explain}
|
||||
|
||||
session_feature_diagnostic_for_issue =
|
||||
see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information
|
||||
|
||||
session_feature_diagnostic_help =
|
||||
add `#![feature({$feature})]` to the crate attributes to enable
|
@ -41,6 +41,7 @@ fluent_messages! {
|
||||
const_eval => "../locales/en-US/const_eval.ftl",
|
||||
driver => "../locales/en-US/driver.ftl",
|
||||
expand => "../locales/en-US/expand.ftl",
|
||||
session => "../locales/en-US/session.ftl",
|
||||
interface => "../locales/en-US/interface.ftl",
|
||||
infer => "../locales/en-US/infer.ftl",
|
||||
lint => "../locales/en-US/lint.ftl",
|
||||
|
@ -2,8 +2,13 @@
|
||||
//! compilation. This is used for incremental compilation tests and debug
|
||||
//! output.
|
||||
|
||||
use crate::errors::{CguNotRecorded, IncorrectCguReuseType};
|
||||
use crate::Session;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::{self};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tracing::debug;
|
||||
|
||||
@ -14,6 +19,22 @@ pub enum CguReuse {
|
||||
PostLto,
|
||||
}
|
||||
|
||||
impl fmt::Display for CguReuse {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
CguReuse::No => write!(f, "No"),
|
||||
CguReuse::PreLto => write!(f, "PreLto "),
|
||||
CguReuse::PostLto => write!(f, "PostLto "),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for CguReuse {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum ComparisonKind {
|
||||
Exact,
|
||||
@ -84,7 +105,7 @@ impl CguReuseTracker {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_expected_reuse(&self, diag: &rustc_errors::Handler) {
|
||||
pub fn check_expected_reuse(&self, sess: &Session) {
|
||||
if let Some(ref data) = self.data {
|
||||
let data = data.lock().unwrap();
|
||||
|
||||
@ -98,19 +119,17 @@ impl CguReuseTracker {
|
||||
};
|
||||
|
||||
if error {
|
||||
let at_least = if at_least { "at least " } else { "" };
|
||||
let msg = format!(
|
||||
"CGU-reuse for `{cgu_user_name}` is `{actual_reuse:?}` but \
|
||||
should be {at_least}`{expected_reuse:?}`"
|
||||
);
|
||||
diag.span_err(error_span.0, &msg);
|
||||
let at_least = if at_least { 1 } else { 0 };
|
||||
IncorrectCguReuseType {
|
||||
span: error_span.0,
|
||||
cgu_user_name: &cgu_user_name,
|
||||
actual_reuse,
|
||||
expected_reuse,
|
||||
at_least,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
let msg = format!(
|
||||
"CGU-reuse for `{cgu_user_name}` (mangled: `{cgu_name}`) was \
|
||||
not recorded"
|
||||
);
|
||||
diag.span_fatal(error_span.0, &msg)
|
||||
sess.emit_fatal(CguNotRecorded { cgu_user_name, cgu_name });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
compiler/rustc_session/src/errors.rs
Normal file
45
compiler/rustc_session/src/errors.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use crate as rustc_session;
|
||||
use crate::cgu_reuse_tracker::CguReuse;
|
||||
use rustc_errors::MultiSpan;
|
||||
use rustc_macros::SessionDiagnostic;
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(session::incorrect_cgu_reuse_type)]
|
||||
pub struct IncorrectCguReuseType<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub cgu_user_name: &'a str,
|
||||
pub actual_reuse: CguReuse,
|
||||
pub expected_reuse: CguReuse,
|
||||
pub at_least: u8,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(session::cgu_not_recorded)]
|
||||
pub struct CguNotRecorded<'a> {
|
||||
pub cgu_user_name: &'a str,
|
||||
pub cgu_name: &'a str,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(session::feature_gate_error, code = "E0658")]
|
||||
pub struct FeatureGateError<'a> {
|
||||
#[primary_span]
|
||||
pub span: MultiSpan,
|
||||
pub explain: &'a str,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
#[note(session::feature_diagnostic_for_issue)]
|
||||
pub struct FeatureDiagnosticForIssue {
|
||||
pub n: NonZeroU32,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
#[help(session::feature_diagnostic_help)]
|
||||
pub struct FeatureDiagnosticHelp {
|
||||
pub feature: Symbol,
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
pub mod errors;
|
||||
|
||||
pub mod cgu_reuse_tracker;
|
||||
pub mod utils;
|
||||
|
@ -2,6 +2,7 @@
|
||||
//! It also serves as an input to the parser itself.
|
||||
|
||||
use crate::config::CheckCfg;
|
||||
use crate::errors::{FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError};
|
||||
use crate::lint::{
|
||||
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
|
||||
};
|
||||
@ -11,7 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::sync::{Lock, Lrc};
|
||||
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
|
||||
use rustc_errors::{
|
||||
error_code, fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId,
|
||||
fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId,
|
||||
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey,
|
||||
};
|
||||
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
|
||||
@ -112,7 +113,7 @@ pub fn feature_err_issue<'a>(
|
||||
.map(|err| err.cancel());
|
||||
}
|
||||
|
||||
let mut err = sess.span_diagnostic.struct_span_err_with_code(span, explain, error_code!(E0658));
|
||||
let mut err = sess.create_err(FeatureGateError { span, explain });
|
||||
add_feature_diagnostics_for_issue(&mut err, sess, feature, issue);
|
||||
err
|
||||
}
|
||||
@ -130,6 +131,8 @@ pub fn feature_warn<'a>(sess: &'a ParseSess, feature: Symbol, span: Span, explai
|
||||
///
|
||||
/// This variant allows you to control whether it is a library or language feature.
|
||||
/// Almost always, you want to use this for a language feature. If so, prefer `feature_warn`.
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
pub fn feature_warn_issue<'a>(
|
||||
sess: &'a ParseSess,
|
||||
feature: Symbol,
|
||||
@ -172,14 +175,12 @@ pub fn add_feature_diagnostics_for_issue<'a>(
|
||||
issue: GateIssue,
|
||||
) {
|
||||
if let Some(n) = find_feature_issue(feature, issue) {
|
||||
err.note(&format!(
|
||||
"see issue #{n} <https://github.com/rust-lang/rust/issues/{n}> for more information"
|
||||
));
|
||||
err.subdiagnostic(FeatureDiagnosticForIssue { n });
|
||||
}
|
||||
|
||||
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
|
||||
if sess.unstable_features.is_nightly_build() {
|
||||
err.help(&format!("add `#![feature({feature})]` to the crate attributes to enable"));
|
||||
err.subdiagnostic(FeatureDiagnosticHelp { feature });
|
||||
}
|
||||
}
|
||||
|
||||
@ -372,6 +373,8 @@ impl ParseSess {
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
pub fn struct_err(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
@ -380,16 +383,22 @@ impl ParseSess {
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
self.span_diagnostic.struct_warn(msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
|
||||
self.span_diagnostic.struct_fatal(msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
pub fn struct_diagnostic<G: EmissionGuarantee>(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
|
Loading…
Reference in New Issue
Block a user