Skip to content

Commit 728224d

Browse files
committed
Show inferred opaque types with #[rustc_regions]
1 parent f23bca7 commit 728224d

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,17 @@ fn do_mir_borrowck<'a, 'tcx>(
221221
// write unit-tests, as well as helping with debugging.
222222
nll::dump_mir_results(infcx, MirSource::item(def_id), &body, &regioncx, &opt_closure_req);
223223

224-
// We also have a `#[rustc_nll]` annotation that causes us to dump
224+
// We also have a `#[rustc_regions]` annotation that causes us to dump
225225
// information.
226-
nll::dump_annotation(infcx, &body, def_id, &regioncx, &opt_closure_req, &mut errors_buffer);
226+
nll::dump_annotation(
227+
infcx,
228+
&body,
229+
def_id,
230+
&regioncx,
231+
&opt_closure_req,
232+
&opaque_type_values,
233+
&mut errors_buffer,
234+
);
227235

228236
// The various `flow_*` structures can be large. We drop `flow_inits` here
229237
// so it doesn't overlap with the others below. This reduces peak memory

src/librustc_mir/borrow_check/nll.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
355355
mir_def_id: DefId,
356356
regioncx: &RegionInferenceContext<'tcx>,
357357
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
358+
opaque_type_values: &FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>>,
358359
errors_buffer: &mut Vec<Diagnostic>,
359360
) {
360361
let tcx = infcx.tcx;
@@ -370,7 +371,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
370371
// viewing the intraprocedural state, the -Zdump-mir output is
371372
// better.
372373

373-
if let Some(closure_region_requirements) = closure_region_requirements {
374+
let mut err = if let Some(closure_region_requirements) = closure_region_requirements {
374375
let mut err = tcx.sess.diagnostic().span_note_diag(body.span, "external requirements");
375376

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

391-
err.buffer(errors_buffer);
392+
err
392393
} else {
393394
let mut err = tcx.sess.diagnostic().span_note_diag(body.span, "no external requirements");
394395
regioncx.annotate(tcx, &mut err);
395396

396-
err.buffer(errors_buffer);
397+
err
398+
};
399+
400+
if !opaque_type_values.is_empty() {
401+
err.note(&format!("Inferred opaque type values:\n{:#?}", opaque_type_values));
397402
}
403+
404+
err.buffer(errors_buffer);
398405
}
399406

400407
fn for_each_region_constraint(

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12261226
revealed_ty={:?}",
12271227
output_ty, opaque_type_map, revealed_ty
12281228
);
1229+
// Make sure that the inferred types are well-formed. I'm
1230+
// not entirely sure this is needed (the HIR type check
1231+
// didn't do this) but it seems sensible to prevent opaque
1232+
// types hiding ill-formed types.
1233+
obligations.obligations.push(traits::Obligation::new(
1234+
ObligationCause::dummy(),
1235+
param_env,
1236+
ty::Predicate::WellFormed(revealed_ty),
1237+
));
12291238
obligations.add(
12301239
infcx
12311240
.at(&ObligationCause::dummy(), param_env)

0 commit comments

Comments
 (0)