diff options
| author | bors <bors@rust-lang.org> | 2021-06-21 06:56:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-06-21 06:56:51 +0000 |
| commit | d789de67dcbd22c017a3a4cccac22510f61bf50c (patch) | |
| tree | c630b392580d798686540b6d26ad70cd095cdf1f /compiler/rustc_session/src | |
| parent | 3824017f8e57ce9dac6d69a1ce07f41c7034f82d (diff) | |
| parent | 88b01f1178a86e22742103e8e1f385163e844fbd (diff) | |
| download | rust-d789de67dcbd22c017a3a4cccac22510f61bf50c.tar.gz rust-d789de67dcbd22c017a3a4cccac22510f61bf50c.zip | |
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.
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 5 |
2 files changed, 13 insertions, 5 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index af24358fe64..5afa8e6a09a 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -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( diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 86b8389a670..d8a58ee18cd 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -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(|| { |
