Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 870a01a

Browse files
committedFeb 8, 2024
Auto merge of rust-lang#120558 - oli-obk:missing_impl_item_ice, r=estebank
Stop bailing out from compilation just because there were incoherent traits fixes rust-lang#120343 but also has a lot of "type annotations needed" fallout. Some are fixed in the second commit.
2 parents 384b02c + a59a1e7 commit 870a01a

File tree

50 files changed

+490
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+490
-146
lines changed
 

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,10 @@ pub(super) fn check_type_bounds<'tcx>(
19901990
impl_ty: ty::AssocItem,
19911991
impl_trait_ref: ty::TraitRef<'tcx>,
19921992
) -> Result<(), ErrorGuaranteed> {
1993+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1994+
// other `Foo` impls are incoherent.
1995+
tcx.ensure().coherent_trait(impl_trait_ref.def_id)?;
1996+
19931997
let param_env = tcx.param_env(impl_ty.def_id);
19941998
debug!(?param_env);
19951999

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,11 @@ fn check_associated_item(
10051005
enter_wf_checking_ctxt(tcx, span, item_id, |wfcx| {
10061006
let item = tcx.associated_item(item_id);
10071007

1008+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1009+
// other `Foo` impls are incoherent.
1010+
tcx.ensure()
1011+
.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?;
1012+
10081013
let self_ty = match item.container {
10091014
ty::TraitContainer => tcx.types.self_param,
10101015
ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(),
@@ -1291,6 +1296,9 @@ fn check_impl<'tcx>(
12911296
// therefore don't need to be WF (the trait's `Self: Trait` predicate
12921297
// won't hold).
12931298
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
1299+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1300+
// other `Foo` impls are incoherent.
1301+
tcx.ensure().coherent_trait(trait_ref.def_id)?;
12941302
let trait_ref = wfcx.normalize(
12951303
ast_trait_ref.path.span,
12961304
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),

‎compiler/rustc_hir_analysis/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
169169

170170
tcx.sess.time("coherence_checking", || {
171171
// Check impls constrain their parameters
172-
let mut res =
172+
let res =
173173
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_impl_wf(module));
174174

175175
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
176-
res = res.and(tcx.ensure().coherent_trait(trait_def_id));
176+
let _ = tcx.ensure().coherent_trait(trait_def_id);
177177
}
178178
// these queries are executed for side-effects (error reporting):
179179
res.and(tcx.ensure().crate_inherent_impls(()))

‎compiler/rustc_hir_typeck/src/callee.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn check_legal_trait_for_method_call(
4141
receiver: Option<Span>,
4242
expr_span: Span,
4343
trait_id: DefId,
44-
) {
44+
) -> Result<(), ErrorGuaranteed> {
4545
if tcx.lang_items().drop_trait() == Some(trait_id) {
4646
let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
4747
errors::ExplicitDestructorCallSugg::Snippet {
@@ -51,8 +51,9 @@ pub fn check_legal_trait_for_method_call(
5151
} else {
5252
errors::ExplicitDestructorCallSugg::Empty(span)
5353
};
54-
tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg });
54+
return Err(tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg }));
5555
}
56+
tcx.coherent_trait(trait_id)
5657
}
5758

5859
#[derive(Debug)]

0 commit comments

Comments
 (0)
This repository has been archived.