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

Commit a80aabc

Browse files
authored
Rollup 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 5bd222d + 32b44ec commit a80aabc

File tree

48 files changed

+497
-137
lines changed

Some content is hidden

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

48 files changed

+497
-137
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,10 @@ fn check_associated_item(
10061006
enter_wf_checking_ctxt(tcx, span, item_id, |wfcx| {
10071007
let item = tcx.associated_item(item_id);
10081008

1009+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1010+
// other `Foo` impls are incoherent.
1011+
tcx.ensure().coherent_trait(tcx.local_parent(item_id))?;
1012+
10091013
let self_ty = match item.container {
10101014
ty::TraitContainer => tcx.types.self_param,
10111015
ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(),
@@ -1292,6 +1296,9 @@ fn check_impl<'tcx>(
12921296
// therefore don't need to be WF (the trait's `Self: Trait` predicate
12931297
// won't hold).
12941298
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)?;
12951302
let trait_ref = wfcx.normalize(
12961303
ast_trait_ref.path.span,
12971304
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_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,12 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23642364
return e;
23652365
}
23662366

2367+
if let Err(guar) = self.tcx.ensure().coherent_trait(trait_ref.def_id()) {
2368+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
2369+
// other `Foo` impls are incoherent.
2370+
return guar;
2371+
}
2372+
23672373
// This is kind of a hack: it frequently happens that some earlier
23682374
// error prevents types from being fully inferred, and then we get
23692375
// a bunch of uninteresting errors saying something like "<generic
@@ -2659,6 +2665,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26592665
if let Some(e) = self.tainted_by_errors() {
26602666
return e;
26612667
}
2668+
2669+
if let Err(guar) =
2670+
self.tcx.ensure().coherent_trait(self.tcx.parent(data.projection_ty.def_id))
2671+
{
2672+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
2673+
// other `Foo` impls are incoherent.
2674+
return guar;
2675+
}
26622676
let subst = data
26632677
.projection_ty
26642678
.args

library/core/src/primitive_docs.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -448,22 +448,6 @@ mod prim_unit {}
448448
#[doc(hidden)]
449449
impl () {}
450450

451-
// Fake impl that's only really used for docs.
452-
#[cfg(doc)]
453-
#[stable(feature = "rust1", since = "1.0.0")]
454-
impl Clone for () {
455-
fn clone(&self) -> Self {
456-
loop {}
457-
}
458-
}
459-
460-
// Fake impl that's only really used for docs.
461-
#[cfg(doc)]
462-
#[stable(feature = "rust1", since = "1.0.0")]
463-
impl Copy for () {
464-
// empty
465-
}
466-
467451
#[rustc_doc_primitive = "pointer"]
468452
#[doc(alias = "ptr")]
469453
#[doc(alias = "*")]
@@ -1690,23 +1674,3 @@ mod prim_fn {}
16901674
// See src/librustdoc/passes/collect_trait_impls.rs:collect_trait_impls
16911675
#[doc(hidden)]
16921676
impl<Ret, T> fn(T) -> Ret {}
1693-
1694-
// Fake impl that's only really used for docs.
1695-
#[cfg(doc)]
1696-
#[stable(feature = "rust1", since = "1.0.0")]
1697-
#[doc(fake_variadic)]
1698-
/// This trait is implemented on function pointers with any number of arguments.
1699-
impl<Ret, T> Clone for fn(T) -> Ret {
1700-
fn clone(&self) -> Self {
1701-
loop {}
1702-
}
1703-
}
1704-
1705-
// Fake impl that's only really used for docs.
1706-
#[cfg(doc)]
1707-
#[stable(feature = "rust1", since = "1.0.0")]
1708-
#[doc(fake_variadic)]
1709-
/// This trait is implemented on function pointers with any number of arguments.
1710-
impl<Ret, T> Copy for fn(T) -> Ret {
1711-
// empty
1712-
}

tests/ui/associated-consts/issue-105330.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
1414

1515
fn main<A: TraitWAssocConst<A=32>>() {
1616
//~^ ERROR E0658
17+
//~| ERROR E0131
1718
foo::<Demo>();
1819
}

tests/ui/associated-consts/issue-105330.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ LL | impl TraitWAssocConst for impl Demo {
4343
|
4444
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
4545

46-
error: aborting due to 5 previous errors
46+
error[E0131]: `main` function is not allowed to have generic parameters
47+
--> $DIR/issue-105330.rs:15:8
48+
|
49+
LL | fn main<A: TraitWAssocConst<A=32>>() {
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters
51+
52+
error: aborting due to 6 previous errors
4753

48-
Some errors have detailed explanations: E0404, E0562, E0658.
49-
For more information about an error, try `rustc --explain E0404`.
54+
Some errors have detailed explanations: E0131, E0404, E0562, E0658.
55+
For more information about an error, try `rustc --explain E0131`.

tests/ui/async-await/in-trait/coherence-constrained.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ impl Foo for Bar {
1212
type T = ();
1313

1414
async fn foo(&self) {}
15-
//~^ ERROR type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
1615
}
1716

1817
impl Foo for Bar {
1918
//~^ ERROR conflicting implementations of trait `Foo` for type `Bar`
2019
type T = ();
2120

2221
async fn foo(&self) {}
23-
//~^ ERROR type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
2422
}
2523

2624
fn main() {}
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
2-
--> $DIR/coherence-constrained.rs:14:5
3-
|
4-
LL | async fn foo(&self) {}
5-
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`
6-
7-
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
8-
--> $DIR/coherence-constrained.rs:22:5
9-
|
10-
LL | async fn foo(&self) {}
11-
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`
12-
131
error[E0119]: conflicting implementations of trait `Foo` for type `Bar`
14-
--> $DIR/coherence-constrained.rs:18:1
2+
--> $DIR/coherence-constrained.rs:17:1
153
|
164
LL | impl Foo for Bar {
175
| ---------------- first implementation here
186
...
197
LL | impl Foo for Bar {
208
| ^^^^^^^^^^^^^^^^ conflicting implementation for `Bar`
219

22-
error: aborting due to 3 previous errors
10+
error: aborting due to 1 previous error
2311

24-
Some errors have detailed explanations: E0119, E0284.
25-
For more information about an error, try `rustc --explain E0119`.
12+
For more information about this error, try `rustc --explain E0119`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! A regression test for #120343. The overlap error was previously
2+
//! silenced in coherence because projecting `<() as ToUnit>::Unit`
3+
//! failed. Then then silenced the missing items error in the `ToUnit`
4+
//! impl, causing us to not emit any errors and ICEing due to a
5+
//! `span_delay_bug`.
6+
7+
trait ToUnit {
8+
type Unit;
9+
}
10+
11+
impl<T> ToUnit for *const T {}
12+
//~^ ERROR: not all trait items implemented
13+
14+
trait Overlap<T> {}
15+
16+
impl<T> Overlap<T> for T {}
17+
18+
impl<T> Overlap<<*const T as ToUnit>::Unit> for T {}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)