about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-07-27 05:27:45 +0000
committerMichael Goulet <michael@errs.io>2022-07-27 05:34:29 +0000
commit1694ea187392a4832a5d69fa008b1e5ff13fe584 (patch)
tree185761bc268a7a3dcf49754d06ad1a21f5b315a7
parentc9b31839b624345d59fda6e595b9abae71fcea13 (diff)
downloadrust-1694ea187392a4832a5d69fa008b1e5ff13fe584.tar.gz
rust-1694ea187392a4832a5d69fa008b1e5ff13fe584.zip
use check_region_obligations_and_report_errors in more places to avoid ICEs
-rw-r--r--compiler/rustc_typeck/src/check/compare_method.rs6
-rw-r--r--compiler/rustc_typeck/src/coherence/builtin.rs4
-rw-r--r--compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs3
-rw-r--r--src/test/ui/coercion/issue-53475.rs13
-rw-r--r--src/test/ui/coercion/issue-53475.stderr14
5 files changed, 34 insertions, 6 deletions
diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs
index af77efc3c2d..e3ac23686b6 100644
--- a/compiler/rustc_typeck/src/check/compare_method.rs
+++ b/compiler/rustc_typeck/src/check/compare_method.rs
@@ -1154,8 +1154,10 @@ pub(crate) fn compare_const_impl<'tcx>(
         }
 
         let outlives_environment = OutlivesEnvironment::new(param_env);
-        infcx
-            .resolve_regions_and_report_errors(impl_c.def_id.expect_local(), &outlives_environment);
+        infcx.check_region_obligations_and_report_errors(
+            impl_c.def_id.expect_local(),
+            &outlives_environment,
+        );
     });
 }
 
diff --git a/compiler/rustc_typeck/src/coherence/builtin.rs b/compiler/rustc_typeck/src/coherence/builtin.rs
index d8e42729ff3..1e404fda035 100644
--- a/compiler/rustc_typeck/src/coherence/builtin.rs
+++ b/compiler/rustc_typeck/src/coherence/builtin.rs
@@ -349,7 +349,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
 
                     // Finally, resolve all regions.
                     let outlives_env = OutlivesEnvironment::new(param_env);
-                    infcx.resolve_regions_and_report_errors(impl_did, &outlives_env);
+                    infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
                 }
             }
             _ => {
@@ -606,7 +606,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
 
         // Finally, resolve all regions.
         let outlives_env = OutlivesEnvironment::new(param_env);
-        infcx.resolve_regions_and_report_errors(impl_did, &outlives_env);
+        infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
 
         CoerceUnsizedInfo { custom_kind: kind }
     })
diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs
index f16888345e9..74abb71a18e 100644
--- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs
+++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs
@@ -158,8 +158,7 @@ fn get_impl_substs<'tcx>(
         implied_bounds,
         tcx.hir().local_def_id_to_hir_id(impl1_def_id),
     );
-    infcx.process_registered_region_obligations(outlives_env.region_bound_pairs(), param_env);
-    infcx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env);
+    infcx.check_region_obligations_and_report_errors(impl1_def_id, &outlives_env);
     let Ok(impl2_substs) = infcx.fully_resolve(impl2_substs) else {
         let span = tcx.def_span(impl1_def_id);
         tcx.sess.emit_err(SubstsOnOverriddenImpl { span });
diff --git a/src/test/ui/coercion/issue-53475.rs b/src/test/ui/coercion/issue-53475.rs
new file mode 100644
index 00000000000..3770c024fb9
--- /dev/null
+++ b/src/test/ui/coercion/issue-53475.rs
@@ -0,0 +1,13 @@
+#![feature(coerce_unsized)]
+
+use std::any::Any;
+use std::ops::CoerceUnsized;
+
+struct Foo<T> {
+    data: Box<T>,
+}
+
+impl<T> CoerceUnsized<Foo<dyn Any>> for Foo<T> {}
+//~^ ERROR the parameter type `T` may not live long enough
+
+fn main() {}
diff --git a/src/test/ui/coercion/issue-53475.stderr b/src/test/ui/coercion/issue-53475.stderr
new file mode 100644
index 00000000000..522c50dca95
--- /dev/null
+++ b/src/test/ui/coercion/issue-53475.stderr
@@ -0,0 +1,14 @@
+error[E0310]: the parameter type `T` may not live long enough
+  --> $DIR/issue-53475.rs:10:1
+   |
+LL | impl<T> CoerceUnsized<Foo<dyn Any>> for Foo<T> {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
+   |
+help: consider adding an explicit lifetime bound...
+   |
+LL | impl<T: 'static> CoerceUnsized<Foo<dyn Any>> for Foo<T> {}
+   |       +++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0310`.