Skip to content

Commit 4edefe2

Browse files
committed
fix ICE 1/2
1 parent 7f06dcf commit 4edefe2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

compiler/rustc_hir_typeck/src/opaque_types.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use rustc_middle::ty::{DefiningScopeKind, EarlyBinder, OpaqueHiddenType, OpaqueTypeKey, Ty};
1+
use rustc_middle::ty::{
2+
DefiningScopeKind, EarlyBinder, OpaqueHiddenType, OpaqueTypeKey, Ty, TypeVisitableExt,
3+
};
24
use rustc_trait_selection::opaque_types::{
35
InvalidOpaqueTypeArgs, check_opaque_type_parameter_valid,
46
};
@@ -46,6 +48,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4648
) => continue,
4749
}
4850

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+
4960
let hidden_type = hidden_type.remap_generic_params_to_declaration_params(
5061
opaque_type_key,
5162
tcx,
@@ -81,12 +92,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8192
opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)],
8293
) {
8394
let tcx = self.tcx;
84-
let typeck_results = &mut *self.typeck_results.borrow_mut();
8595
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 {
8799
let guar =
88100
tcx.dcx().span_err(hidden_type.span, "non-defining use in the defining scope");
89-
typeck_results
101+
self.typeck_results
102+
.borrow_mut()
90103
.concrete_opaque_types
91104
.insert(key.def_id, OpaqueHiddenType::new_error(tcx, guar));
92105
self.set_tainted_by_errors(guar);

0 commit comments

Comments
 (0)