Skip to content

Commit 76f0a8c

Browse files
authored
Rollup merge of #114147 - compiler-errors:missing-rpitits, r=spastorino
Insert RPITITs that were shadowed by missing ADTs that resolve to [type error] Comment inline explains how this can happen. Fixes #113903
2 parents 06eebbe + a4ac773 commit 76f0a8c

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
756756
);
757757
ocx.resolve_regions_and_report_errors(impl_m_def_id, &outlives_env)?;
758758

759-
let mut collected_tys = FxHashMap::default();
759+
let mut remapped_types = FxHashMap::default();
760760
for (def_id, (ty, args)) in collected_types {
761761
match infcx.fully_resolve((ty, args)) {
762762
Ok((ty, args)) => {
@@ -806,19 +806,37 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
806806
Ok(ty) => ty,
807807
Err(guar) => Ty::new_error(tcx, guar),
808808
};
809-
collected_tys.insert(def_id, ty::EarlyBinder::bind(ty));
809+
remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
810810
}
811811
Err(err) => {
812812
let reported = tcx.sess.delay_span_bug(
813813
return_span,
814814
format!("could not fully resolve: {ty} => {err:?}"),
815815
);
816-
collected_tys.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
816+
remapped_types.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
817817
}
818818
}
819819
}
820820

821-
Ok(&*tcx.arena.alloc(collected_tys))
821+
// We may not collect all RPITITs that we see in the HIR for a trait signature
822+
// because an RPITIT was located within a missing item. Like if we have a sig
823+
// returning `-> Missing<impl Sized>`, that gets converted to `-> [type error]`,
824+
// and when walking through the signature we end up never collecting the def id
825+
// of the `impl Sized`. Insert that here, so we don't ICE later.
826+
for assoc_item in tcx.associated_types_for_impl_traits_in_associated_fn(trait_m.def_id) {
827+
if !remapped_types.contains_key(assoc_item) {
828+
remapped_types.insert(
829+
*assoc_item,
830+
ty::EarlyBinder::bind(Ty::new_error_with_message(
831+
tcx,
832+
return_span,
833+
"missing synthetic item for RPITIT",
834+
)),
835+
);
836+
}
837+
}
838+
839+
Ok(&*tcx.arena.alloc(remapped_types))
822840
}
823841

824842
struct ImplTraitInTraitCollector<'a, 'tcx> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// issue: 113903
2+
3+
#![feature(return_position_impl_trait_in_trait)]
4+
5+
use std::ops::Deref;
6+
7+
pub trait Tr {
8+
fn w() -> impl Deref<Target = Missing<impl Sized>>;
9+
//~^ ERROR cannot find type `Missing` in this scope
10+
}
11+
12+
impl Tr for () {
13+
fn w() -> &'static () {
14+
&()
15+
}
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `Missing` in this scope
2+
--> $DIR/rpitit-shadowed-by-missing-adt.rs:8:35
3+
|
4+
LL | fn w() -> impl Deref<Target = Missing<impl Sized>>;
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)