Skip to content

Commit 1694ea1

Browse files
use check_region_obligations_and_report_errors in more places to avoid ICEs
1 parent c9b3183 commit 1694ea1

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

compiler/rustc_typeck/src/check/compare_method.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1154,8 +1154,10 @@ pub(crate) fn compare_const_impl<'tcx>(
11541154
}
11551155

11561156
let outlives_environment = OutlivesEnvironment::new(param_env);
1157-
infcx
1158-
.resolve_regions_and_report_errors(impl_c.def_id.expect_local(), &outlives_environment);
1157+
infcx.check_region_obligations_and_report_errors(
1158+
impl_c.def_id.expect_local(),
1159+
&outlives_environment,
1160+
);
11591161
});
11601162
}
11611163

compiler/rustc_typeck/src/coherence/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
349349

350350
// Finally, resolve all regions.
351351
let outlives_env = OutlivesEnvironment::new(param_env);
352-
infcx.resolve_regions_and_report_errors(impl_did, &outlives_env);
352+
infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
353353
}
354354
}
355355
_ => {
@@ -606,7 +606,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
606606

607607
// Finally, resolve all regions.
608608
let outlives_env = OutlivesEnvironment::new(param_env);
609-
infcx.resolve_regions_and_report_errors(impl_did, &outlives_env);
609+
infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
610610

611611
CoerceUnsizedInfo { custom_kind: kind }
612612
})

compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ fn get_impl_substs<'tcx>(
158158
implied_bounds,
159159
tcx.hir().local_def_id_to_hir_id(impl1_def_id),
160160
);
161-
infcx.process_registered_region_obligations(outlives_env.region_bound_pairs(), param_env);
162-
infcx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env);
161+
infcx.check_region_obligations_and_report_errors(impl1_def_id, &outlives_env);
163162
let Ok(impl2_substs) = infcx.fully_resolve(impl2_substs) else {
164163
let span = tcx.def_span(impl1_def_id);
165164
tcx.sess.emit_err(SubstsOnOverriddenImpl { span });

src/test/ui/coercion/issue-53475.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(coerce_unsized)]
2+
3+
use std::any::Any;
4+
use std::ops::CoerceUnsized;
5+
6+
struct Foo<T> {
7+
data: Box<T>,
8+
}
9+
10+
impl<T> CoerceUnsized<Foo<dyn Any>> for Foo<T> {}
11+
//~^ ERROR the parameter type `T` may not live long enough
12+
13+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0310]: the parameter type `T` may not live long enough
2+
--> $DIR/issue-53475.rs:10:1
3+
|
4+
LL | impl<T> CoerceUnsized<Foo<dyn Any>> for Foo<T> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
6+
|
7+
help: consider adding an explicit lifetime bound...
8+
|
9+
LL | impl<T: 'static> CoerceUnsized<Foo<dyn Any>> for Foo<T> {}
10+
| +++++++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0310`.

0 commit comments

Comments
 (0)