|
1 | | -use rustc_middle::ty::{DefiningScopeKind, EarlyBinder, OpaqueHiddenType, OpaqueTypeKey, Ty}; |
| 1 | +use rustc_middle::ty::{ |
| 2 | + DefiningScopeKind, EarlyBinder, OpaqueHiddenType, OpaqueTypeKey, Ty, TypeVisitableExt, |
| 3 | +}; |
2 | 4 | use rustc_trait_selection::opaque_types::{ |
3 | 5 | InvalidOpaqueTypeArgs, check_opaque_type_parameter_valid, |
4 | 6 | }; |
@@ -46,6 +48,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
46 | 48 | ) => continue, |
47 | 49 | } |
48 | 50 |
|
| 51 | + if hidden_type.ty.has_non_region_infer() { |
| 52 | + let guar = |
| 53 | + tcx.dcx().span_err(hidden_type.span, "non-defining use in the defining scope"); |
| 54 | + typeck_results |
| 55 | + .concrete_opaque_types |
| 56 | + .insert(opaque_type_key.def_id, OpaqueHiddenType::new_error(tcx, guar)); |
| 57 | + self.set_tainted_by_errors(guar); |
| 58 | + } |
| 59 | + |
49 | 60 | let hidden_type = hidden_type.remap_generic_params_to_declaration_params( |
50 | 61 | opaque_type_key, |
51 | 62 | tcx, |
@@ -81,12 +92,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
81 | 92 | opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)], |
82 | 93 | ) { |
83 | 94 | let tcx = self.tcx; |
84 | | - let typeck_results = &mut *self.typeck_results.borrow_mut(); |
85 | 95 | for &(key, hidden_type) in opaque_types { |
86 | | - let Some(&expected) = typeck_results.concrete_opaque_types.get(&key.def_id) else { |
| 96 | + let Some(&expected) = |
| 97 | + self.typeck_results.borrow_mut().concrete_opaque_types.get(&key.def_id) |
| 98 | + else { |
87 | 99 | let guar = |
88 | 100 | tcx.dcx().span_err(hidden_type.span, "non-defining use in the defining scope"); |
89 | | - typeck_results |
| 101 | + self.typeck_results |
| 102 | + .borrow_mut() |
90 | 103 | .concrete_opaque_types |
91 | 104 | .insert(key.def_id, OpaqueHiddenType::new_error(tcx, guar)); |
92 | 105 | self.set_tainted_by_errors(guar); |
|
0 commit comments