Skip to content

Commit a4ac773

Browse files
Insert RPITITs that were shadowed by missing ADTs that resolve to type error
1 parent 9339f44 commit a4ac773

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
@@ -760,7 +760,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
760760
);
761761
ocx.resolve_regions_and_report_errors(impl_m_def_id, &outlives_env)?;
762762

763-
let mut collected_tys = FxHashMap::default();
763+
let mut remapped_types = FxHashMap::default();
764764
for (def_id, (ty, args)) in collected_types {
765765
match infcx.fully_resolve((ty, args)) {
766766
Ok((ty, args)) => {
@@ -810,19 +810,37 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
810810
Ok(ty) => ty,
811811
Err(guar) => Ty::new_error(tcx, guar),
812812
};
813-
collected_tys.insert(def_id, ty::EarlyBinder::bind(ty));
813+
remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
814814
}
815815
Err(err) => {
816816
let reported = tcx.sess.delay_span_bug(
817817
return_span,
818818
format!("could not fully resolve: {ty} => {err:?}"),
819819
);
820-
collected_tys.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
820+
remapped_types.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
821821
}
822822
}
823823
}
824824

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

828846
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)