diff options
Diffstat (limited to 'compiler/rustc_session/src/config.rs')
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 89 |
1 files changed, 64 insertions, 25 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 86a078f4a38..530c1a06f8f 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -3,14 +3,14 @@ pub use crate::options::*; -use crate::lint; use crate::search_paths::SearchPath; use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind}; use crate::{early_error, early_warn, Session}; +use crate::{lint, HashStableContext}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::impl_stable_hash_via_hash; +use rustc_data_structures::stable_hasher::ToStableHashKey; use rustc_target::abi::{Align, TargetDataLayout}; use rustc_target::spec::{LinkerFlavor, SplitDebuginfo, Target, TargetTriple, TargetWarnings}; use rustc_target::spec::{PanicStrategy, SanitizerSet, TARGETS}; @@ -78,7 +78,7 @@ pub enum CFProtection { Full, } -#[derive(Clone, Copy, Debug, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Hash, HashStable_Generic)] pub enum OptLevel { No, // -O0 Less, // -O1 @@ -88,8 +88,6 @@ pub enum OptLevel { SizeMin, // -Oz } -impl_stable_hash_via_hash!(OptLevel); - /// This is what the `LtoCli` values get mapped to after resolving defaults and /// and taking other command line options into account. /// @@ -230,15 +228,13 @@ impl SwitchWithOptPath { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic)] #[derive(Encodable, Decodable)] pub enum SymbolManglingVersion { Legacy, V0, } -impl_stable_hash_via_hash!(SymbolManglingVersion); - #[derive(Clone, Copy, Debug, PartialEq, Hash)] pub enum DebugInfo { None, @@ -277,7 +273,7 @@ impl FromStr for SplitDwarfKind { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, HashStable_Generic)] #[derive(Encodable, Decodable)] pub enum OutputType { Bitcode, @@ -290,7 +286,13 @@ pub enum OutputType { DepInfo, } -impl_stable_hash_via_hash!(OutputType); +impl<HCX: HashStableContext> ToStableHashKey<HCX> for OutputType { + type KeyType = Self; + + fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType { + *self + } +} impl OutputType { fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool { @@ -396,7 +398,7 @@ pub enum TrimmedDefPaths { /// *Do not* switch `BTreeMap` out for an unsorted container type! That would break /// dependency tracking for command-line arguments. Also only hash keys, since tracking /// should only depend on the output types, not the paths they're written to. -#[derive(Clone, Debug, Hash)] +#[derive(Clone, Debug, Hash, HashStable_Generic)] pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>); impl OutputTypes { @@ -472,6 +474,11 @@ pub struct ExternEntry { /// This can be disabled with the `noprelude` option like /// `--extern noprelude:name`. pub add_prelude: bool, + /// The extern entry shouldn't be considered for unused dependency warnings. + /// + /// `--extern nounused:std=/path/to/lib/libstd.rlib`. This is used to + /// suppress `unused-crate-dependencies` warnings. + pub nounused_dep: bool, } #[derive(Clone, Debug)] @@ -510,7 +517,7 @@ impl Externs { impl ExternEntry { fn new(location: ExternLocation) -> ExternEntry { - ExternEntry { location, is_private_dep: false, add_prelude: false } + ExternEntry { location, is_private_dep: false, add_prelude: false, nounused_dep: false } } pub fn files(&self) -> Option<impl Iterator<Item = &CanonicalizedPath>> { @@ -585,7 +592,7 @@ impl Input { } } -#[derive(Clone, Hash, Debug)] +#[derive(Clone, Hash, Debug, HashStable_Generic)] pub struct OutputFilenames { pub out_directory: PathBuf, filestem: String, @@ -594,8 +601,6 @@ pub struct OutputFilenames { pub outputs: OutputTypes, } -impl_stable_hash_via_hash!(OutputFilenames); - pub const RLINK_EXT: &str = "rlink"; pub const RUST_CGU_EXT: &str = "rcgu"; pub const DWARF_OBJECT_EXT: &str = "dwo"; @@ -752,7 +757,7 @@ impl Default for Options { real_rust_source_base_dir: None, edition: DEFAULT_EDITION, json_artifact_notifications: false, - json_unused_externs: false, + json_unused_externs: JsonUnusedExterns::No, json_future_incompat: false, pretty: None, working_dir: RealFileName::LocalPath(std::env::current_dir().unwrap()), @@ -808,15 +813,14 @@ impl DebuggingOptions { } // The type of entry function, so users can have their own entry functions -#[derive(Copy, Clone, PartialEq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Hash, Debug, HashStable_Generic)] pub enum EntryFnType { Main, Start, } -impl_stable_hash_via_hash!(EntryFnType); - #[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, Encodable, Decodable)] +#[derive(HashStable_Generic)] pub enum CrateType { Executable, Dylib, @@ -826,8 +830,6 @@ pub enum CrateType { ProcMacro, } -impl_stable_hash_via_hash!(CrateType); - impl CrateType { /// When generated, is this crate type an archive? pub fn is_archive(&self) -> bool { @@ -1041,6 +1043,7 @@ impl CrateCheckConfig { sym::target_has_atomic_load_store, sym::target_has_atomic, sym::target_has_atomic_equal_alignment, + sym::target_feature, sym::panic, sym::sanitize, sym::debug_assertions, @@ -1084,6 +1087,10 @@ impl CrateCheckConfig { .into_iter() .map(|sanitizer| Symbol::intern(sanitizer.as_str().unwrap())); + // Unknown possible values: + // - `feature` + // - `target_feature` + // No-values for name in [ sym::doc, @@ -1491,10 +1498,37 @@ pub fn parse_color(matches: &getopts::Matches) -> ColorConfig { pub struct JsonConfig { pub json_rendered: HumanReadableErrorType, pub json_artifact_notifications: bool, - pub json_unused_externs: bool, + pub json_unused_externs: JsonUnusedExterns, pub json_future_incompat: bool, } +/// Report unused externs in event stream +#[derive(Copy, Clone)] +pub enum JsonUnusedExterns { + /// Do not + No, + /// Report, but do not exit with failure status for deny/forbid + Silent, + /// Report, and also exit with failure status for deny/forbid + Loud, +} + +impl JsonUnusedExterns { + pub fn is_enabled(&self) -> bool { + match self { + JsonUnusedExterns::No => false, + JsonUnusedExterns::Loud | JsonUnusedExterns::Silent => true, + } + } + + pub fn is_loud(&self) -> bool { + match self { + JsonUnusedExterns::No | JsonUnusedExterns::Silent => false, + JsonUnusedExterns::Loud => true, + } + } +} + /// Parse the `--json` flag. /// /// The first value returned is how to render JSON diagnostics, and the second @@ -1504,7 +1538,7 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig { HumanReadableErrorType::Default; let mut json_color = ColorConfig::Never; let mut json_artifact_notifications = false; - let mut json_unused_externs = false; + let mut json_unused_externs = JsonUnusedExterns::No; let mut json_future_incompat = false; for option in matches.opt_strs("json") { // For now conservatively forbid `--color` with `--json` since `--json` @@ -1522,7 +1556,8 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig { "diagnostic-short" => json_rendered = HumanReadableErrorType::Short, "diagnostic-rendered-ansi" => json_color = ColorConfig::Always, "artifacts" => json_artifact_notifications = true, - "unused-externs" => json_unused_externs = true, + "unused-externs" => json_unused_externs = JsonUnusedExterns::Loud, + "unused-externs-silent" => json_unused_externs = JsonUnusedExterns::Silent, "future-incompat" => json_future_incompat = true, s => early_error( ErrorOutputType::default(), @@ -2134,6 +2169,7 @@ pub fn parse_externs( let mut is_private_dep = false; let mut add_prelude = true; + let mut nounused_dep = false; if let Some(opts) = options { if !is_unstable_enabled { early_error( @@ -2155,6 +2191,7 @@ pub fn parse_externs( ); } } + "nounused" => nounused_dep = true, _ => early_error(error_format, &format!("unknown --extern option `{opt}`")), } } @@ -2163,6 +2200,8 @@ pub fn parse_externs( // Crates start out being not private, and go to being private `priv` // is specified. entry.is_private_dep |= is_private_dep; + // likewise `nounused` + entry.nounused_dep |= nounused_dep; // If any flag is missing `noprelude`, then add to the prelude. entry.add_prelude |= add_prelude; } @@ -2218,7 +2257,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { check_debug_option_stability(&debugging_opts, error_format, json_rendered); - if !debugging_opts.unstable_options && json_unused_externs { + if !debugging_opts.unstable_options && json_unused_externs.is_enabled() { early_error( error_format, "the `-Z unstable-options` flag must also be passed to enable \ |
