Skip to content

Commit

Permalink
use check_region_obligations_and_report_errors in more places to avoi…
Browse files Browse the repository at this point in the history
…d ICEs
  • Loading branch information
compiler-errors committed Jul 27, 2022
1 parent c9b3183 commit 1694ea1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
_ => {
Expand Down Expand Up @@ -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 }
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/coercion/issue-53475.rs
Original file line number Diff line number Diff line change
@@ -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() {}
14 changes: 14 additions & 0 deletions src/test/ui/coercion/issue-53475.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 1694ea1

Please sign in to comment.