|
1 | 1 | use rustc_hir::def::DefKind;
|
2 |
| -use rustc_hir_analysis::errors::TaitForwardCompat2; |
3 | 2 | use rustc_infer::traits::ObligationCause;
|
4 | 3 | use rustc_middle::ty::{
|
5 | 4 | self, DefiningScopeKind, EarlyBinder, OpaqueHiddenType, OpaqueTypeKey, TypeVisitableExt,
|
6 | 5 | TypingMode,
|
7 | 6 | };
|
8 | 7 | use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
|
9 | 8 | use rustc_trait_selection::opaque_types::{
|
10 |
| - NonDefiningUseReason, opaque_type_has_defining_use_args, |
| 9 | + NonDefiningUseReason, opaque_type_has_defining_use_args, report_item_does_not_constrain_error, |
11 | 10 | };
|
12 | 11 | use rustc_trait_selection::solve;
|
13 | 12 | use tracing::{debug, instrument};
|
@@ -43,7 +42,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
43 | 42 |
|
44 | 43 | enum UsageKind<'tcx> {
|
45 | 44 | None,
|
46 |
| - NonDefiningUse(OpaqueHiddenType<'tcx>), |
| 45 | + NonDefiningUse(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>), |
47 | 46 | UnconstrainedHiddenType(OpaqueHiddenType<'tcx>),
|
48 | 47 | HasDefiningUse,
|
49 | 48 | }
|
@@ -106,18 +105,16 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
106 | 105 | if let Some(guar) = self.tainted_by_errors() {
|
107 | 106 | guar
|
108 | 107 | } else {
|
109 |
| - self.tcx.dcx().emit_err(TaitForwardCompat2 { |
110 |
| - span: self |
111 |
| - .tcx |
112 |
| - .def_ident_span(self.body_id) |
113 |
| - .unwrap_or_else(|| self.tcx.def_span(self.body_id)), |
114 |
| - opaque_type_span: self.tcx.def_span(def_id), |
115 |
| - opaque_type: self.tcx.def_path_str(def_id), |
116 |
| - }) |
| 108 | + report_item_does_not_constrain_error(self.tcx, self.body_id, def_id, None) |
117 | 109 | }
|
118 | 110 | }
|
119 |
| - UsageKind::NonDefiningUse(hidden_type) => { |
120 |
| - tcx.dcx().span_err(hidden_type.span, "non-defining use in the defining scope") |
| 111 | + UsageKind::NonDefiningUse(opaque_type_key, hidden_type) => { |
| 112 | + report_item_does_not_constrain_error( |
| 113 | + self.tcx, |
| 114 | + self.body_id, |
| 115 | + def_id, |
| 116 | + Some((opaque_type_key, hidden_type.span)), |
| 117 | + ) |
121 | 118 | }
|
122 | 119 | UsageKind::UnconstrainedHiddenType(hidden_type) => {
|
123 | 120 | let infer_var = hidden_type
|
@@ -166,7 +163,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
166 | 163 | );
|
167 | 164 | return UsageKind::HasDefiningUse;
|
168 | 165 | }
|
169 |
| - _ => return UsageKind::NonDefiningUse(hidden_type), |
| 166 | + _ => return UsageKind::NonDefiningUse(opaque_type_key, hidden_type), |
170 | 167 | };
|
171 | 168 | }
|
172 | 169 |
|
|
0 commit comments