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