1
Fork 0

Auto merge of #85775 - adamrk:warn-unused-target-fields, r=nagisa

Emit warnings for unused fields in custom targets.

Add a warning which lists any fields in a custom target `json` file that aren't used. Currently unrecognized fields are ignored so, for example, a typo in the `json` will silently produce a target which isn't the one intended.
This commit is contained in:
bors 2021-06-21 06:56:51 +00:00
commit d789de67dc
7 changed files with 235 additions and 91 deletions

View file

@ -12,7 +12,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::impl_stable_hash_via_hash;
use rustc_target::abi::{Align, TargetDataLayout};
use rustc_target::spec::{SplitDebuginfo, Target, TargetTriple};
use rustc_target::spec::{SplitDebuginfo, Target, TargetTriple, TargetWarnings};
use rustc_serialize::json;
@ -899,9 +899,11 @@ pub(super) fn build_target_config(
target_override: Option<Target>,
sysroot: &PathBuf,
) -> Target {
let target_result =
target_override.map_or_else(|| Target::search(&opts.target_triple, sysroot), Ok);
let target = target_result.unwrap_or_else(|e| {
let target_result = target_override.map_or_else(
|| Target::search(&opts.target_triple, sysroot),
|t| Ok((t, TargetWarnings::empty())),
);
let (target, target_warnings) = target_result.unwrap_or_else(|e| {
early_error(
opts.error_format,
&format!(
@ -911,6 +913,9 @@ pub(super) fn build_target_config(
),
)
});
for warning in target_warnings.warning_messages() {
early_warn(opts.error_format, &warning)
}
if !matches!(target.pointer_width, 16 | 32 | 64) {
early_error(

View file

@ -1284,9 +1284,12 @@ pub fn build_session(
let target_cfg = config::build_target_config(&sopts, target_override, &sysroot);
let host_triple = TargetTriple::from_triple(config::host_triple());
let host = Target::search(&host_triple, &sysroot).unwrap_or_else(|e| {
let (host, target_warnings) = Target::search(&host_triple, &sysroot).unwrap_or_else(|e| {
early_error(sopts.error_format, &format!("Error loading host specification: {}", e))
});
for warning in target_warnings.warning_messages() {
early_warn(sopts.error_format, &warning)
}
let loader = file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
let hash_kind = sopts.debugging_opts.src_hash_algorithm.unwrap_or_else(|| {