Slightly refactor the dumping of HIR analysis data
This commit is contained in:
32
compiler/rustc_hir_analysis/src/variance/dump.rs
Normal file
32
compiler/rustc_hir_analysis/src/variance/dump.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
pub(crate) fn variances(tcx: TyCtxt<'_>) {
|
||||
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
|
||||
for id in tcx.hir().items() {
|
||||
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue };
|
||||
|
||||
let variances = tcx.variances_of(id.owner_id);
|
||||
|
||||
tcx.dcx().emit_err(crate::errors::VariancesOf {
|
||||
span: tcx.def_span(id.owner_id),
|
||||
variances: format!("{variances:?}"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for id in tcx.hir().items() {
|
||||
if !tcx.has_attr(id.owner_id, sym::rustc_variance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let variances = tcx.variances_of(id.owner_id);
|
||||
|
||||
tcx.dcx().emit_err(crate::errors::VariancesOf {
|
||||
span: tcx.def_span(id.owner_id),
|
||||
variances: format!("{variances:?}"),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,7 @@ mod constraints;
|
||||
/// Code to solve constraints and write out the results.
|
||||
mod solve;
|
||||
|
||||
/// Code to write unit tests of variance.
|
||||
pub mod test;
|
||||
pub(crate) mod dump;
|
||||
|
||||
/// Code for transforming variances.
|
||||
mod xform;
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::ErrorGuaranteed;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
|
||||
let mut res = Ok(());
|
||||
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
|
||||
for id in tcx.hir().items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
|
||||
let variances_of = tcx.variances_of(id.owner_id);
|
||||
|
||||
res = Err(tcx.dcx().emit_err(errors::VariancesOf {
|
||||
span: tcx.def_span(id.owner_id),
|
||||
variances_of: format!("{variances_of:?}"),
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For unit testing: check for a special "rustc_variance"
|
||||
// attribute and report an error with various results if found.
|
||||
for id in tcx.hir().items() {
|
||||
if tcx.has_attr(id.owner_id, sym::rustc_variance) {
|
||||
let variances_of = tcx.variances_of(id.owner_id);
|
||||
|
||||
res = Err(tcx.dcx().emit_err(errors::VariancesOf {
|
||||
span: tcx.def_span(id.owner_id),
|
||||
variances_of: format!("{variances_of:?}"),
|
||||
}));
|
||||
}
|
||||
}
|
||||
res
|
||||
}
|
||||
Reference in New Issue
Block a user