From edee23ee25d813547587fdd6bcd3677606839fad Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 28 Dec 2019 15:50:06 +0000 Subject: [PATCH] Avoid unnecessary opaque type errors in borrowck --- src/librustc_mir/borrow_check/mod.rs | 3 +++ src/librustc_mir/borrow_check/nll.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 1843d4bf72d..da9bdc8b4b0 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -136,6 +136,9 @@ fn do_mir_borrowck<'a, 'tcx>( // Gather the upvars of a closure, if any. let tables = tcx.typeck_tables_of(def_id); + if tables.tainted_by_errors { + infcx.set_tainted_by_errors(); + } let upvars: Vec<_> = tables .upvar_list .get(&def_id) diff --git a/src/librustc_mir/borrow_check/nll.rs b/src/librustc_mir/borrow_check/nll.rs index e4e5fe35d7f..4c1ee9582c1 100644 --- a/src/librustc_mir/borrow_check/nll.rs +++ b/src/librustc_mir/borrow_check/nll.rs @@ -282,6 +282,11 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>( let (closure_region_requirements, nll_errors) = regioncx.solve(infcx, &body, def_id, polonius_output.clone()); + if !nll_errors.is_empty() { + // Suppress unhelpful extra errors in `infer_opaque_types`. + infcx.set_tainted_by_errors(); + } + let remapped_opaque_tys = regioncx.infer_opaque_types(&infcx, opaque_type_values, body.span); NllOutput {