Rollup merge of #123997 - compiler-errors:self-res, r=fmease

Delay span bug when `Self` kw resolves to `DefKind::{Mod,Trait}`

Catch the case where `kw::Self` is recovered in the parser and causes us to subsequently resolve `&self`'s implicit type to something that's not a type.

This check could be made more accurate, though I'm not sure how hard we have to try here.

Fixes #123988
This commit is contained in:
Matthias Krüger 2024-04-17 05:44:53 +02:00 committed by GitHub
commit 90af17ddcb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 0 deletions

View file

@ -1866,6 +1866,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
self.set_tainted_by_errors(e);
Ty::new_error(self.tcx(), e)
}
Res::Def(..) => {
assert_eq!(
path.segments.get(0).map(|seg| seg.ident.name),
Some(kw::SelfUpper),
"only expected incorrect resolution for `Self`"
);
Ty::new_error(
self.tcx(),
self.tcx().dcx().span_delayed_bug(span, "incorrect resolution for `Self`"),
)
}
_ => span_bug!(span, "unexpected resolution: {:?}", path.res),
}
}