Skip to content

Commit

Permalink
translations(rustc_session): migrate the file cgu_reuse_tracker
Browse files Browse the repository at this point in the history
This commit migrates the errors that indicates an incorrect
CGU type and the fatal error that indicates that a CGU has
not been correctly recorded
  • Loading branch information
beowolx committed Aug 26, 2022
1 parent 8a13871 commit 706452e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/session.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
incorrect_cgu_reuse_type =
CGU-reuse for `{$cgu_user_name}` is `{$actual_reuse}` but should be `{$at_least}``${expected_reuse}`

cgu_not_recorded =
CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded`
1 change: 1 addition & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fluent_messages! {
builtin_macros => "../locales/en-US/builtin_macros.ftl",
const_eval => "../locales/en-US/const_eval.ftl",
expand => "../locales/en-US/expand.ftl",
session => "../locales/en-US/session.ftl",
interface => "../locales/en-US/interface.ftl",
lint => "../locales/en-US/lint.ftl",
parser => "../locales/en-US/parser.ftl",
Expand Down
34 changes: 29 additions & 5 deletions compiler/rustc_session/src/cgu_reuse_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
//! compilation. This is used for incremental compilation tests and debug
//! output.

use crate::errors::IncorrectCguReuseType;
// use crate::errors::{CguNotRecorded, IncorrectCguReuseType};
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;

Expand All @@ -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,
Expand Down Expand Up @@ -99,18 +120,21 @@ 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);
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)
// CguNotRecorded { cgu_user_name, cgu_name };
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate as rustc_session;
use crate::cgu_reuse_tracker::CguReuse;
use rustc_macros::SessionDiagnostic;
use rustc_span::Span;

#[derive(SessionDiagnostic)]
#[error(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: &'a str,
}

// #[derive(SessionDiagnostic)]
// #[fatal(session::cgu_not_recorded)]
// pub struct CguNotRecorded<'a> {
// pub cgu_user_name: &'a str,
// pub cgu_name: &'a str,
// }
3 changes: 3 additions & 0 deletions compiler/rustc_session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
#![feature(map_many_mut)]
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

#[macro_use]
extern crate rustc_macros;
pub mod errors;

pub mod cgu_reuse_tracker;
pub mod utils;
Expand Down

0 comments on commit 706452e

Please sign in to comment.