Skip to content

Commit 1fec163

Browse files
authored
Unrolled build for #147833
Rollup merge of #147833 - aDotInTheVoid:rdj-shuffle, r=camelid rustdoc-json: move `target` to `json::conversions` It belongs here, because it moves from a `rustc_*` type to a `rustdoc_json_types` type. r? ```````@GuillaumeGomez```````
2 parents c8f22ca + 329682d commit 1fec163

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

src/librustdoc/json/conversions.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use rustc_abi::ExternAbi;
66
use rustc_ast::ast;
7+
use rustc_data_structures::fx::FxHashSet;
78
use rustc_data_structures::thin_vec::ThinVec;
89
use rustc_hir as hir;
910
use rustc_hir::attrs::{self, DeprecatedSince};
@@ -988,3 +989,55 @@ fn format_integer_type(it: rustc_abi::IntegerType) -> String {
988989
}
989990
.to_owned()
990991
}
992+
993+
pub(super) fn target(sess: &rustc_session::Session) -> Target {
994+
// Build a set of which features are enabled on this target
995+
let globally_enabled_features: FxHashSet<&str> =
996+
sess.unstable_target_features.iter().map(|name| name.as_str()).collect();
997+
998+
// Build a map of target feature stability by feature name
999+
use rustc_target::target_features::Stability;
1000+
let feature_stability: FxHashMap<&str, Stability> = sess
1001+
.target
1002+
.rust_target_features()
1003+
.iter()
1004+
.copied()
1005+
.map(|(name, stability, _)| (name, stability))
1006+
.collect();
1007+
1008+
Target {
1009+
triple: sess.opts.target_triple.tuple().into(),
1010+
target_features: sess
1011+
.target
1012+
.rust_target_features()
1013+
.iter()
1014+
.copied()
1015+
.filter(|(_, stability, _)| {
1016+
// Describe only target features which the user can toggle
1017+
stability.toggle_allowed().is_ok()
1018+
})
1019+
.map(|(name, stability, implied_features)| {
1020+
TargetFeature {
1021+
name: name.into(),
1022+
unstable_feature_gate: match stability {
1023+
Stability::Unstable(feature_gate) => Some(feature_gate.as_str().into()),
1024+
_ => None,
1025+
},
1026+
implies_features: implied_features
1027+
.iter()
1028+
.copied()
1029+
.filter(|name| {
1030+
// Imply only target features which the user can toggle
1031+
feature_stability
1032+
.get(name)
1033+
.map(|stability| stability.toggle_allowed().is_ok())
1034+
.unwrap_or(false)
1035+
})
1036+
.map(String::from)
1037+
.collect(),
1038+
globally_enabled: globally_enabled_features.contains(name),
1039+
}
1040+
})
1041+
.collect(),
1042+
}
1043+
}

src/librustdoc/json/mod.rs

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::io::{BufWriter, Write, stdout};
1414
use std::path::PathBuf;
1515
use std::rc::Rc;
1616

17-
use rustc_data_structures::fx::FxHashSet;
1817
use rustc_hir::def_id::{DefId, DefIdSet};
1918
use rustc_middle::ty::TyCtxt;
2019
use rustc_session::Session;
@@ -123,58 +122,6 @@ impl<'tcx> JsonRenderer<'tcx> {
123122
}
124123
}
125124

126-
fn target(sess: &rustc_session::Session) -> types::Target {
127-
// Build a set of which features are enabled on this target
128-
let globally_enabled_features: FxHashSet<&str> =
129-
sess.unstable_target_features.iter().map(|name| name.as_str()).collect();
130-
131-
// Build a map of target feature stability by feature name
132-
use rustc_target::target_features::Stability;
133-
let feature_stability: FxHashMap<&str, Stability> = sess
134-
.target
135-
.rust_target_features()
136-
.iter()
137-
.copied()
138-
.map(|(name, stability, _)| (name, stability))
139-
.collect();
140-
141-
types::Target {
142-
triple: sess.opts.target_triple.tuple().into(),
143-
target_features: sess
144-
.target
145-
.rust_target_features()
146-
.iter()
147-
.copied()
148-
.filter(|(_, stability, _)| {
149-
// Describe only target features which the user can toggle
150-
stability.toggle_allowed().is_ok()
151-
})
152-
.map(|(name, stability, implied_features)| {
153-
types::TargetFeature {
154-
name: name.into(),
155-
unstable_feature_gate: match stability {
156-
Stability::Unstable(feature_gate) => Some(feature_gate.as_str().into()),
157-
_ => None,
158-
},
159-
implies_features: implied_features
160-
.iter()
161-
.copied()
162-
.filter(|name| {
163-
// Imply only target features which the user can toggle
164-
feature_stability
165-
.get(name)
166-
.map(|stability| stability.toggle_allowed().is_ok())
167-
.unwrap_or(false)
168-
})
169-
.map(String::from)
170-
.collect(),
171-
globally_enabled: globally_enabled_features.contains(name),
172-
}
173-
})
174-
.collect(),
175-
}
176-
}
177-
178125
impl<'tcx> JsonRenderer<'tcx> {
179126
pub(crate) fn init(
180127
krate: clean::Crate,
@@ -317,7 +264,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
317264
// multiple targets: https://github.com/rust-lang/rust/pull/137632
318265
//
319266
// We want to describe a single target, so pass tcx.sess rather than tcx.
320-
let target = target(self.tcx.sess);
267+
let target = conversions::target(self.tcx.sess);
321268

322269
debug!("Constructing Output");
323270
let output_crate = types::Crate {

0 commit comments

Comments
 (0)