Skip to content

Commit

Permalink
Rollup merge of rust-lang#101041 - LuisCardosoOliveira:translation-re…
Browse files Browse the repository at this point in the history
…name-attr-warning-pt2, r=davidtwco

translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2

# Description

This is the second part of the `rustc_session` [migration](rust-lang#100717 (comment)).

**Please only review this [commit](rust-lang@5018581) that belongs to the part 2. The other ones are from the PR [rust-lang#100753](rust-lang#100753) that is not yet merged.**

In this PR, we migrate the files `session.rs` and `config.rs`.

Please not that we have to `allow` the lints rules in some functions from `session.rs` because they are (at least I believe) part of the diagnostic machinery.
  • Loading branch information
Dylan-DPC authored Sep 8, 2022
2 parents ac2d840 + 0e497a7 commit 8928eb4
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 75 deletions.
42 changes: 42 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/session.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,45 @@ session_feature_diagnostic_for_issue =
session_feature_diagnostic_help =
add `#![feature({$feature})]` to the crate attributes to enable
session_not_circumvent_feature = `-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature gates, except when testing error paths in the CTFE engine
session_profile_use_file_does_not_exist = file `{$path}` passed to `-C profile-use` does not exist.
session_linker_plugin_lto_windows_not_supported = linker plugin based LTO is not supported together with `-C prefer-dynamic` when targeting Windows-like targets
session_profile_sample_use_file_does_not_exist = file `{$path}` passed to `-C profile-sample-use` does not exist.
session_target_requires_unwind_tables = target requires unwind tables, they cannot be disabled with `-C force-unwind-tables=no`
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target
session_cannot_mix_and_match_sanitizers = `-Zsanitizer={$first}` is incompatible with `-Zsanitizer={$second}`
session_cannot_enable_crt_static_linux = sanitizer is incompatible with statically linked libc, disable it using `-C target-feature=-crt-static`
session_sanitizer_cfi_enabled = `-Zsanitizer=cfi` requires `-Clto`
session_unstable_virtual_function_elimination = `-Zvirtual-function-elimination` requires `-Clto`
session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is greater than 5
session_target_invalid_address_space = invalid address space `{$addr_space}` for `{$cause}` in "data-layout": {$err}
session_target_invalid_bits = invalid {$kind} `{$bit}` for `{$cause}` in "data-layout": {$err}
session_target_missing_alignment = missing alignment for `{$cause}` in "data-layout"
session_target_invalid_alignment = invalid alignment for `{$cause}` in "data-layout": {$err}
session_target_inconsistent_architecture = inconsistent target specification: "data-layout" claims architecture is {$dl}-endian, while "target-endian" is `{$target}`
session_target_inconsistent_pointer_width = inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}`
session_target_invalid_bits_size = {$err}
session_target_stack_protector_not_supported = `-Z stack-protector={$stack_protector}` is not supported for target {$target_triple} and will be ignored
session_split_debuginfo_unstable_platform = `-Csplit-debuginfo={$debuginfo}` is unstable on this platform
7 changes: 6 additions & 1 deletion compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_span::edition::LATEST_STABLE_EDITION;
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
use rustc_span::{edition::Edition, Span, DUMMY_SP};
use rustc_target::spec::PanicStrategy;
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
use std::borrow::Cow;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::num::ParseIntError;
use std::path::{Path, PathBuf};

/// Error type for `Diagnostic`'s `suggestions` field, indicating that
Expand Down Expand Up @@ -91,6 +92,10 @@ into_diagnostic_arg_using_display!(
Edition,
Ident,
MacroRulesNormalizedIdent,
ParseIntError,
StackProtector,
&TargetTriple,
SplitDebuginfo
);

impl IntoDiagnosticArg for bool {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ impl<'tcx> TyCtxt<'tcx> {
output_filenames: OutputFilenames,
) -> GlobalCtxt<'tcx> {
let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| {
s.fatal(&err);
s.emit_fatal(err);
});
let interners = CtxtInterners::new(arena);
let common_types = CommonTypes::new(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
let max_atomic_width = sess.target.max_atomic_width();
let atomic_cas = sess.target.atomic_cas;
let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| {
sess.fatal(&err);
sess.emit_fatal(err);
});

let mut ret = CrateConfig::default();
Expand Down
131 changes: 129 additions & 2 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::num::NonZeroU32;

use crate as rustc_session;
use crate::cgu_reuse_tracker::CguReuse;
use rustc_errors::MultiSpan;
use crate::{self as rustc_session, SessionDiagnostic};
use rustc_errors::{fluent, DiagnosticBuilder, Handler, MultiSpan};
use rustc_macros::SessionDiagnostic;
use rustc_span::{Span, Symbol};
use rustc_target::abi::TargetDataLayoutErrors;
use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple};

#[derive(SessionDiagnostic)]
#[diag(session::incorrect_cgu_reuse_type)]
Expand Down Expand Up @@ -43,3 +45,128 @@ pub struct FeatureDiagnosticForIssue {
pub struct FeatureDiagnosticHelp {
pub feature: Symbol,
}

impl SessionDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, !> {
let mut diag;
match self {
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
diag = sess.struct_fatal(fluent::session::target_invalid_address_space);
diag.set_arg("addr_space", addr_space);
diag.set_arg("cause", cause);
diag.set_arg("err", err);
diag
}
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
diag = sess.struct_fatal(fluent::session::target_invalid_bits);
diag.set_arg("kind", kind);
diag.set_arg("bit", bit);
diag.set_arg("cause", cause);
diag.set_arg("err", err);
diag
}
TargetDataLayoutErrors::MissingAlignment { cause } => {
diag = sess.struct_fatal(fluent::session::target_missing_alignment);
diag.set_arg("cause", cause);
diag
}
TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
diag = sess.struct_fatal(fluent::session::target_invalid_alignment);
diag.set_arg("cause", cause);
diag.set_arg("err", err);
diag
}
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
diag = sess.struct_fatal(fluent::session::target_inconsistent_architecture);
diag.set_arg("dl", dl);
diag.set_arg("target", target);
diag
}
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
diag = sess.struct_fatal(fluent::session::target_inconsistent_pointer_width);
diag.set_arg("pointer_size", pointer_size);
diag.set_arg("target", target);
diag
}
TargetDataLayoutErrors::InvalidBitsSize { err } => {
diag = sess.struct_fatal(fluent::session::target_invalid_bits_size);
diag.set_arg("err", err);
diag
}
}
}
}

#[derive(SessionDiagnostic)]
#[diag(session::not_circumvent_feature)]
pub struct NotCircumventFeature;

#[derive(SessionDiagnostic)]
#[diag(session::linker_plugin_lto_windows_not_supported)]
pub struct LinkerPluginToWindowsNotSupported;

#[derive(SessionDiagnostic)]
#[diag(session::profile_use_file_does_not_exist)]
pub struct ProfileUseFileDoesNotExist<'a> {
pub path: &'a std::path::Path,
}

#[derive(SessionDiagnostic)]
#[diag(session::profile_sample_use_file_does_not_exist)]
pub struct ProfileSampleUseFileDoesNotExist<'a> {
pub path: &'a std::path::Path,
}

#[derive(SessionDiagnostic)]
#[diag(session::target_requires_unwind_tables)]
pub struct TargetRequiresUnwindTables;

#[derive(SessionDiagnostic)]
#[diag(session::sanitizer_not_supported)]
pub struct SanitizerNotSupported {
pub us: String,
}

#[derive(SessionDiagnostic)]
#[diag(session::sanitizers_not_supported)]
pub struct SanitizersNotSupported {
pub us: String,
}

#[derive(SessionDiagnostic)]
#[diag(session::cannot_mix_and_match_sanitizers)]
pub struct CannotMixAndMatchSanitizers {
pub first: String,
pub second: String,
}

#[derive(SessionDiagnostic)]
#[diag(session::cannot_enable_crt_static_linux)]
pub struct CannotEnableCrtStaticLinux;

#[derive(SessionDiagnostic)]
#[diag(session::sanitizer_cfi_enabled)]
pub struct SanitizerCfiEnabled;

#[derive(SessionDiagnostic)]
#[diag(session::unstable_virtual_function_elimination)]
pub struct UnstableVirtualFunctionElimination;

#[derive(SessionDiagnostic)]
#[diag(session::unsupported_dwarf_version)]
pub struct UnsupportedDwarfVersion {
pub dwarf_version: u32,
}

#[derive(SessionDiagnostic)]
#[diag(session::target_stack_protector_not_supported)]
pub struct StackProtectorNotSupportedForTarget<'a> {
pub stack_protector: StackProtector,
pub target_triple: &'a TargetTriple,
}

#[derive(SessionDiagnostic)]
#[diag(session::split_debuginfo_unstable_platform)]
pub struct SplitDebugInfoUnstablePlatform {
pub debuginfo: SplitDebuginfo,
}
Loading

0 comments on commit 8928eb4

Please sign in to comment.