Skip to content

Commit ce22dd9

Browse files
committed
WIP
1 parent 2e43d06 commit ce22dd9

File tree

8 files changed

+617
-39
lines changed

8 files changed

+617
-39
lines changed

src/librustdoc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ rustdoc-json-types = { path = "../rustdoc-json-types" }
2222
tracing = "0.1"
2323
tracing-tree = "0.2.0"
2424
once_cell = "1.10.0"
25+
# @Note hmmmmm
26+
# rustc_apfloat = { path = "../../compiler/rustc_apfloat" }
2527

2628
[dependencies.tracing-subscriber]
2729
version = "0.3.3"

src/librustdoc/clean/types.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_typeck::check::intrinsic::intrinsic_operation_unsafety;
3636
use crate::clean::cfg::Cfg;
3737
use crate::clean::external_path;
3838
use crate::clean::inline::{self, print_inlined_const};
39-
use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_const};
39+
use crate::clean::utils::is_literal_expr;
4040
use crate::clean::Clean;
4141
use crate::core::DocContext;
4242
use crate::formats::cache::Cache;
@@ -2338,6 +2338,10 @@ impl Constant {
23382338
self.kind.value(tcx)
23392339
}
23402340

2341+
pub(crate) fn value_html(&self, cx: &Context<'_>) -> Option<String> {
2342+
self.kind.value_html(cx)
2343+
}
2344+
23412345
pub(crate) fn is_literal(&self, tcx: TyCtxt<'_>) -> bool {
23422346
self.kind.is_literal(tcx)
23432347
}
@@ -2349,7 +2353,7 @@ impl ConstantKind {
23492353
ConstantKind::TyConst { ref expr } => expr.clone(),
23502354
ConstantKind::Extern { def_id } => print_inlined_const(tcx, def_id),
23512355
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
2352-
print_const_expr(tcx, body)
2356+
super::utils::print_const_expr(tcx, body)
23532357
}
23542358
}
23552359
}
@@ -2358,7 +2362,16 @@ impl ConstantKind {
23582362
match *self {
23592363
ConstantKind::TyConst { .. } | ConstantKind::Anonymous { .. } => None,
23602364
ConstantKind::Extern { def_id } | ConstantKind::Local { def_id, .. } => {
2361-
print_evaluated_const(tcx, def_id)
2365+
super::utils::print_evaluated_const(tcx, def_id)
2366+
}
2367+
}
2368+
}
2369+
2370+
pub(crate) fn value_html(&self, cx: &Context<'_>) -> Option<String> {
2371+
match *self {
2372+
ConstantKind::TyConst { .. } | ConstantKind::Anonymous { .. } => None,
2373+
ConstantKind::Extern { def_id } | ConstantKind::Local { def_id, .. } => {
2374+
super::utils::print_evaluated_const_html(def_id, cx)
23622375
}
23632376
}
23642377
}

src/librustdoc/clean/utils.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,26 @@ pub(crate) fn print_evaluated_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<St
276276
})
277277
}
278278

279+
// @Task migrate to mod html::format
280+
// @Task don't return Option<_> anymore
281+
pub(crate) fn print_evaluated_const_html(
282+
def_id: DefId,
283+
cx: &crate::html::render::Context<'_>,
284+
) -> Option<String> {
285+
cx.tcx().const_eval_poly(def_id).ok().and_then(|val| {
286+
let mut buffer = String::new();
287+
// @Task don't call into that module!
288+
crate::html::format::pretty_const::format_const_value(
289+
&mut buffer,
290+
val,
291+
cx.tcx().type_of(def_id),
292+
cx,
293+
)
294+
.ok()?;
295+
Some(buffer)
296+
})
297+
}
298+
279299
fn format_integer_with_underscore_sep(num: &str) -> String {
280300
let num_chars: Vec<_> = num.chars().collect();
281301
let mut num_start_index = if num_chars.get(0) == Some(&'-') { 1 } else { 0 };
@@ -302,6 +322,7 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
302322
.collect()
303323
}
304324

325+
#[allow(dead_code)] // @Temporary
305326
fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: mir::ConstantKind<'_>) -> String {
306327
// Use a slightly different format for integer types which always shows the actual value.
307328
// For all other types, fallback to the original `pretty_print_const`.

0 commit comments

Comments
 (0)