diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 909262d563e9f..edafc9e7a089f 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -4,6 +4,7 @@ use rustc_abi::ExternAbi; use rustc_ast::ast; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::thin_vec::ThinVec; use rustc_hir as hir; use rustc_hir::attrs::{self, DeprecatedSince}; @@ -988,3 +989,55 @@ fn format_integer_type(it: rustc_abi::IntegerType) -> String { } .to_owned() } + +pub(super) fn target(sess: &rustc_session::Session) -> Target { + // Build a set of which features are enabled on this target + let globally_enabled_features: FxHashSet<&str> = + sess.unstable_target_features.iter().map(|name| name.as_str()).collect(); + + // Build a map of target feature stability by feature name + use rustc_target::target_features::Stability; + let feature_stability: FxHashMap<&str, Stability> = sess + .target + .rust_target_features() + .iter() + .copied() + .map(|(name, stability, _)| (name, stability)) + .collect(); + + Target { + triple: sess.opts.target_triple.tuple().into(), + target_features: sess + .target + .rust_target_features() + .iter() + .copied() + .filter(|(_, stability, _)| { + // Describe only target features which the user can toggle + stability.toggle_allowed().is_ok() + }) + .map(|(name, stability, implied_features)| { + TargetFeature { + name: name.into(), + unstable_feature_gate: match stability { + Stability::Unstable(feature_gate) => Some(feature_gate.as_str().into()), + _ => None, + }, + implies_features: implied_features + .iter() + .copied() + .filter(|name| { + // Imply only target features which the user can toggle + feature_stability + .get(name) + .map(|stability| stability.toggle_allowed().is_ok()) + .unwrap_or(false) + }) + .map(String::from) + .collect(), + globally_enabled: globally_enabled_features.contains(name), + } + }) + .collect(), + } +} diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index b724d7e866a05..b020e3d924a46 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -14,7 +14,6 @@ use std::io::{BufWriter, Write, stdout}; use std::path::PathBuf; use std::rc::Rc; -use rustc_data_structures::fx::FxHashSet; use rustc_hir::def_id::{DefId, DefIdSet}; use rustc_middle::ty::TyCtxt; use rustc_session::Session; @@ -123,58 +122,6 @@ impl<'tcx> JsonRenderer<'tcx> { } } -fn target(sess: &rustc_session::Session) -> types::Target { - // Build a set of which features are enabled on this target - let globally_enabled_features: FxHashSet<&str> = - sess.unstable_target_features.iter().map(|name| name.as_str()).collect(); - - // Build a map of target feature stability by feature name - use rustc_target::target_features::Stability; - let feature_stability: FxHashMap<&str, Stability> = sess - .target - .rust_target_features() - .iter() - .copied() - .map(|(name, stability, _)| (name, stability)) - .collect(); - - types::Target { - triple: sess.opts.target_triple.tuple().into(), - target_features: sess - .target - .rust_target_features() - .iter() - .copied() - .filter(|(_, stability, _)| { - // Describe only target features which the user can toggle - stability.toggle_allowed().is_ok() - }) - .map(|(name, stability, implied_features)| { - types::TargetFeature { - name: name.into(), - unstable_feature_gate: match stability { - Stability::Unstable(feature_gate) => Some(feature_gate.as_str().into()), - _ => None, - }, - implies_features: implied_features - .iter() - .copied() - .filter(|name| { - // Imply only target features which the user can toggle - feature_stability - .get(name) - .map(|stability| stability.toggle_allowed().is_ok()) - .unwrap_or(false) - }) - .map(String::from) - .collect(), - globally_enabled: globally_enabled_features.contains(name), - } - }) - .collect(), - } -} - impl<'tcx> JsonRenderer<'tcx> { pub(crate) fn init( krate: clean::Crate, @@ -317,7 +264,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { // multiple targets: https://github.com/rust-lang/rust/pull/137632 // // We want to describe a single target, so pass tcx.sess rather than tcx. - let target = target(self.tcx.sess); + let target = conversions::target(self.tcx.sess); debug!("Constructing Output"); let output_crate = types::Crate {