Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Jul 23, 2022
1 parent 2e43d06 commit ce22dd9
Show file tree
Hide file tree
Showing 8 changed files with 617 additions and 39 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ rustdoc-json-types = { path = "../rustdoc-json-types" }
tracing = "0.1"
tracing-tree = "0.2.0"
once_cell = "1.10.0"
# @Note hmmmmm
# rustc_apfloat = { path = "../../compiler/rustc_apfloat" }

[dependencies.tracing-subscriber]
version = "0.3.3"
Expand Down
19 changes: 16 additions & 3 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_typeck::check::intrinsic::intrinsic_operation_unsafety;
use crate::clean::cfg::Cfg;
use crate::clean::external_path;
use crate::clean::inline::{self, print_inlined_const};
use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_const};
use crate::clean::utils::is_literal_expr;
use crate::clean::Clean;
use crate::core::DocContext;
use crate::formats::cache::Cache;
Expand Down Expand Up @@ -2338,6 +2338,10 @@ impl Constant {
self.kind.value(tcx)
}

pub(crate) fn value_html(&self, cx: &Context<'_>) -> Option<String> {
self.kind.value_html(cx)
}

pub(crate) fn is_literal(&self, tcx: TyCtxt<'_>) -> bool {
self.kind.is_literal(tcx)
}
Expand All @@ -2349,7 +2353,7 @@ impl ConstantKind {
ConstantKind::TyConst { ref expr } => expr.clone(),
ConstantKind::Extern { def_id } => print_inlined_const(tcx, def_id),
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
print_const_expr(tcx, body)
super::utils::print_const_expr(tcx, body)
}
}
}
Expand All @@ -2358,7 +2362,16 @@ impl ConstantKind {
match *self {
ConstantKind::TyConst { .. } | ConstantKind::Anonymous { .. } => None,
ConstantKind::Extern { def_id } | ConstantKind::Local { def_id, .. } => {
print_evaluated_const(tcx, def_id)
super::utils::print_evaluated_const(tcx, def_id)
}
}
}

pub(crate) fn value_html(&self, cx: &Context<'_>) -> Option<String> {
match *self {
ConstantKind::TyConst { .. } | ConstantKind::Anonymous { .. } => None,
ConstantKind::Extern { def_id } | ConstantKind::Local { def_id, .. } => {
super::utils::print_evaluated_const_html(def_id, cx)
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,26 @@ pub(crate) fn print_evaluated_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<St
})
}

// @Task migrate to mod html::format
// @Task don't return Option<_> anymore
pub(crate) fn print_evaluated_const_html(
def_id: DefId,
cx: &crate::html::render::Context<'_>,
) -> Option<String> {
cx.tcx().const_eval_poly(def_id).ok().and_then(|val| {
let mut buffer = String::new();
// @Task don't call into that module!
crate::html::format::pretty_const::format_const_value(
&mut buffer,
val,
cx.tcx().type_of(def_id),
cx,
)
.ok()?;
Some(buffer)
})
}

fn format_integer_with_underscore_sep(num: &str) -> String {
let num_chars: Vec<_> = num.chars().collect();
let mut num_start_index = if num_chars.get(0) == Some(&'-') { 1 } else { 0 };
Expand All @@ -302,6 +322,7 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
.collect()
}

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

0 comments on commit ce22dd9

Please sign in to comment.