Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
}
}
55 changes: 1 addition & 54 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
Loading