Stop bailing out from compilation just because there were incoherent traits
This commit is contained in:
parent
7f1d523cd0
commit
83738a9b1c
46 changed files with 473 additions and 92 deletions
|
@ -1990,6 +1990,10 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||
impl_ty: ty::AssocItem,
|
||||
impl_trait_ref: ty::TraitRef<'tcx>,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
tcx.ensure().coherent_trait(impl_trait_ref.def_id)?;
|
||||
|
||||
let param_env = tcx.param_env(impl_ty.def_id);
|
||||
debug!(?param_env);
|
||||
|
||||
|
|
|
@ -1005,6 +1005,11 @@ fn check_associated_item(
|
|||
enter_wf_checking_ctxt(tcx, span, item_id, |wfcx| {
|
||||
let item = tcx.associated_item(item_id);
|
||||
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
tcx.ensure()
|
||||
.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?;
|
||||
|
||||
let self_ty = match item.container {
|
||||
ty::TraitContainer => tcx.types.self_param,
|
||||
ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(),
|
||||
|
@ -1291,6 +1296,9 @@ fn check_impl<'tcx>(
|
|||
// therefore don't need to be WF (the trait's `Self: Trait` predicate
|
||||
// won't hold).
|
||||
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
tcx.ensure().coherent_trait(trait_ref.def_id)?;
|
||||
let trait_ref = wfcx.normalize(
|
||||
ast_trait_ref.path.span,
|
||||
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
|
||||
|
|
|
@ -169,11 +169,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
|
|||
|
||||
tcx.sess.time("coherence_checking", || {
|
||||
// Check impls constrain their parameters
|
||||
let mut res =
|
||||
let res =
|
||||
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_impl_wf(module));
|
||||
|
||||
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
|
||||
res = res.and(tcx.ensure().coherent_trait(trait_def_id));
|
||||
let _ = tcx.ensure().coherent_trait(trait_def_id);
|
||||
}
|
||||
// these queries are executed for side-effects (error reporting):
|
||||
res.and(tcx.ensure().crate_inherent_impls(()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue