|
5 | 5 | use crate::FnCtxt;
|
6 | 6 | use hir::def_id::LocalDefId;
|
7 | 7 | use rustc_data_structures::fx::FxHashMap;
|
8 |
| -use rustc_errors::ErrorGuaranteed; |
| 8 | +use rustc_errors::{ErrorGuaranteed, StashKey}; |
9 | 9 | use rustc_hir as hir;
|
10 | 10 | use rustc_hir::intravisit::{self, Visitor};
|
11 | 11 | use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
@@ -83,10 +83,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
83 | 83 | wbcx.typeck_results.treat_byte_string_as_slice =
|
84 | 84 | mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice);
|
85 | 85 |
|
86 |
| - if let Some(e) = self.tainted_by_errors() { |
87 |
| - wbcx.typeck_results.tainted_by_errors = Some(e); |
88 |
| - } |
89 |
| - |
90 | 86 | debug!("writeback: typeck results for {:?} are {:#?}", item_def_id, wbcx.typeck_results);
|
91 | 87 |
|
92 | 88 | self.tcx.arena.alloc(wbcx.typeck_results)
|
@@ -119,12 +115,21 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
119 | 115 | ) -> WritebackCx<'cx, 'tcx> {
|
120 | 116 | let owner = body.id().hir_id.owner;
|
121 | 117 |
|
122 |
| - WritebackCx { |
| 118 | + let mut wbcx = WritebackCx { |
123 | 119 | fcx,
|
124 | 120 | typeck_results: ty::TypeckResults::new(owner),
|
125 | 121 | body,
|
126 | 122 | rustc_dump_user_substs,
|
| 123 | + }; |
| 124 | + |
| 125 | + // HACK: We specifically don't want the (opaque) error from tainting our |
| 126 | + // inference context. That'll prevent us from doing opaque type inference |
| 127 | + // later on in borrowck, which affects diagnostic spans pretty negatively. |
| 128 | + if let Some(e) = fcx.tainted_by_errors() { |
| 129 | + wbcx.typeck_results.tainted_by_errors = Some(e); |
127 | 130 | }
|
| 131 | + |
| 132 | + wbcx |
128 | 133 | }
|
129 | 134 |
|
130 | 135 | fn tcx(&self) -> TyCtxt<'tcx> {
|
@@ -579,13 +584,26 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
579 | 584 | continue;
|
580 | 585 | }
|
581 | 586 |
|
582 |
| - let hidden_type = hidden_type.remap_generic_params_to_declaration_params( |
583 |
| - opaque_type_key, |
584 |
| - self.fcx.infcx.tcx, |
585 |
| - true, |
586 |
| - ); |
587 |
| - |
588 |
| - self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type); |
| 587 | + let hidden_type = |
| 588 | + self.tcx().erase_regions(hidden_type.remap_generic_params_to_declaration_params( |
| 589 | + opaque_type_key, |
| 590 | + self.tcx(), |
| 591 | + true, |
| 592 | + )); |
| 593 | + |
| 594 | + if let Some(last_opaque_ty) = self |
| 595 | + .typeck_results |
| 596 | + .concrete_opaque_types |
| 597 | + .insert(opaque_type_key.def_id, hidden_type) |
| 598 | + && last_opaque_ty.ty != hidden_type.ty |
| 599 | + { |
| 600 | + hidden_type |
| 601 | + .report_mismatch(&last_opaque_ty, opaque_type_key.def_id, self.tcx()) |
| 602 | + .stash( |
| 603 | + self.tcx().def_span(opaque_type_key.def_id), |
| 604 | + StashKey::OpaqueHiddenTypeMismatch, |
| 605 | + ); |
| 606 | + } |
589 | 607 | }
|
590 | 608 | }
|
591 | 609 |
|
|
0 commit comments