Skip to content

Commit

Permalink
Show inferred opaque types with #[rustc_regions]
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Feb 14, 2020
1 parent f23bca7 commit 728224d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -221,9 +221,17 @@ fn do_mir_borrowck<'a, 'tcx>(
// write unit-tests, as well as helping with debugging.
nll::dump_mir_results(infcx, MirSource::item(def_id), &body, &regioncx, &opt_closure_req);

// We also have a `#[rustc_nll]` annotation that causes us to dump
// We also have a `#[rustc_regions]` annotation that causes us to dump
// information.
nll::dump_annotation(infcx, &body, def_id, &regioncx, &opt_closure_req, &mut errors_buffer);
nll::dump_annotation(
infcx,
&body,
def_id,
&regioncx,
&opt_closure_req,
&opaque_type_values,
&mut errors_buffer,
);

// The various `flow_*` structures can be large. We drop `flow_inits` here
// so it doesn't overlap with the others below. This reduces peak memory
Expand Down
13 changes: 10 additions & 3 deletions src/librustc_mir/borrow_check/nll.rs
Expand Up @@ -355,6 +355,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
mir_def_id: DefId,
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
opaque_type_values: &FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>>,
errors_buffer: &mut Vec<Diagnostic>,
) {
let tcx = infcx.tcx;
Expand All @@ -370,7 +371,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
// viewing the intraprocedural state, the -Zdump-mir output is
// better.

if let Some(closure_region_requirements) = closure_region_requirements {
let mut err = if let Some(closure_region_requirements) = closure_region_requirements {
let mut err = tcx.sess.diagnostic().span_note_diag(body.span, "external requirements");

regioncx.annotate(tcx, &mut err);
Expand All @@ -388,13 +389,19 @@ pub(super) fn dump_annotation<'a, 'tcx>(
})
.unwrap();

err.buffer(errors_buffer);
err
} else {
let mut err = tcx.sess.diagnostic().span_note_diag(body.span, "no external requirements");
regioncx.annotate(tcx, &mut err);

err.buffer(errors_buffer);
err
};

if !opaque_type_values.is_empty() {
err.note(&format!("Inferred opaque type values:\n{:#?}", opaque_type_values));
}

err.buffer(errors_buffer);
}

fn for_each_region_constraint(
Expand Down
9 changes: 9 additions & 0 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Expand Up @@ -1226,6 +1226,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
revealed_ty={:?}",
output_ty, opaque_type_map, revealed_ty
);
// Make sure that the inferred types are well-formed. I'm
// not entirely sure this is needed (the HIR type check
// didn't do this) but it seems sensible to prevent opaque
// types hiding ill-formed types.
obligations.obligations.push(traits::Obligation::new(
ObligationCause::dummy(),
param_env,
ty::Predicate::WellFormed(revealed_ty),
));
obligations.add(
infcx
.at(&ObligationCause::dummy(), param_env)
Expand Down

0 comments on commit 728224d

Please sign in to comment.