Fix invalid coverage computation when --output-format=json is enabled
This commit is contained in:
@@ -2907,7 +2907,7 @@ fn clean_extern_crate<'tcx>(
|
|||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
&& !cx.output_format.is_json();
|
&& !cx.is_json();
|
||||||
|
|
||||||
let krate_owner_def_id = krate.owner_id.def_id;
|
let krate_owner_def_id = krate.owner_id.def_id;
|
||||||
if please_inline {
|
if please_inline {
|
||||||
@@ -3000,7 +3000,7 @@ fn clean_use_statement_inner<'tcx>(
|
|||||||
// forcefully don't inline if this is not public or if the
|
// forcefully don't inline if this is not public or if the
|
||||||
// #[doc(no_inline)] attribute is present.
|
// #[doc(no_inline)] attribute is present.
|
||||||
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
|
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
|
||||||
let mut denied = cx.output_format.is_json()
|
let mut denied = cx.is_json()
|
||||||
|| !(visibility.is_public()
|
|| !(visibility.is_public()
|
||||||
|| (cx.render_options.document_private && is_visible_from_parent_mod))
|
|| (cx.render_options.document_private && is_visible_from_parent_mod))
|
||||||
|| pub_underscore
|
|| pub_underscore
|
||||||
|
|||||||
@@ -121,6 +121,13 @@ impl<'tcx> DocContext<'tcx> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the JSON output format is enabled for generating the crate content.
|
||||||
|
///
|
||||||
|
/// If another option like `--show-coverage` is enabled, it will return false.
|
||||||
|
pub(crate) fn is_json(&self) -> bool {
|
||||||
|
self.output_format.is_json() && !self.show_coverage
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `DiagCtxt` that can be used to emit warnings and errors.
|
/// Creates a new `DiagCtxt` that can be used to emit warnings and errors.
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ impl<'a, 'b> CoverageCalculator<'a, 'b> {
|
|||||||
|
|
||||||
fn print_results(&self) {
|
fn print_results(&self) {
|
||||||
let output_format = self.ctx.output_format;
|
let output_format = self.ctx.output_format;
|
||||||
|
// In this case we want to ensure that the `OutputFormat` is JSON and NOT the `DocContext`.
|
||||||
if output_format.is_json() {
|
if output_format.is_json() {
|
||||||
println!("{}", self.to_json());
|
println!("{}", self.to_json());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pub(crate) const STRIP_HIDDEN: Pass = Pass {
|
|||||||
/// Strip items marked `#[doc(hidden)]`
|
/// Strip items marked `#[doc(hidden)]`
|
||||||
pub(crate) fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
|
pub(crate) fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
|
||||||
let mut retained = ItemIdSet::default();
|
let mut retained = ItemIdSet::default();
|
||||||
let is_json_output = cx.output_format.is_json() && !cx.show_coverage;
|
let is_json_output = cx.is_json();
|
||||||
|
|
||||||
// strip all #[doc(hidden)] items
|
// strip all #[doc(hidden)] items
|
||||||
let krate = {
|
let krate = {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub(crate) const STRIP_PRIV_IMPORTS: Pass = Pass {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn strip_priv_imports(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
|
pub(crate) fn strip_priv_imports(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
|
||||||
let is_json_output = cx.output_format.is_json() && !cx.show_coverage;
|
let is_json_output = cx.is_json();
|
||||||
ImportStripper {
|
ImportStripper {
|
||||||
tcx: cx.tcx,
|
tcx: cx.tcx,
|
||||||
is_json_output,
|
is_json_output,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub(crate) const STRIP_PRIVATE: Pass = Pass {
|
|||||||
pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
|
pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
|
||||||
// This stripper collects all *retained* nodes.
|
// This stripper collects all *retained* nodes.
|
||||||
let mut retained = ItemIdSet::default();
|
let mut retained = ItemIdSet::default();
|
||||||
let is_json_output = cx.output_format.is_json() && !cx.show_coverage;
|
let is_json_output = cx.is_json();
|
||||||
|
|
||||||
// strip all private items
|
// strip all private items
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.cx.output_format.is_json() {
|
if self.cx.is_json() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user