Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP #1

Closed
wants to merge 1 commit into from
Closed
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
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