Use a diagnostic item instead of filtering for Index::Output

This commit is contained in:
Michael Goulet 2023-04-18 18:55:17 +00:00
parent 770c303c00
commit d84b5f9b3d
3 changed files with 4 additions and 9 deletions

View File

@ -2871,6 +2871,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
base_ty: Ty<'tcx>,
) -> Option<(ErrorGuaranteed, Ty<'tcx>, Ty<'tcx>)> {
let index_trait_def_id = self.tcx.lang_items().index_trait()?;
let index_trait_output_def_id = self.tcx.get_diagnostic_item(sym::IndexOutput)?;
let mut relevant_impls = vec![];
self.tcx.for_each_relevant_impl(index_trait_def_id, base_ty, |impl_def_id| {
@ -2917,15 +2918,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let element_ty = ocx.normalize(
&cause,
self.param_env,
self.tcx.mk_projection(
self.tcx
.associated_items(index_trait_def_id)
.filter_by_name_unhygienic(sym::Output)
.next()
.unwrap()
.def_id,
impl_trait_ref.substs,
),
self.tcx.mk_projection(index_trait_output_def_id, impl_trait_ref.substs),
);
let errors = ocx.select_where_possible();

View File

@ -204,6 +204,7 @@ symbols! {
HashSet,
Hasher,
Implied,
IndexOutput,
Input,
Into,
IntoDiagnostic,

View File

@ -59,6 +59,7 @@
pub trait Index<Idx: ?Sized> {
/// The returned type after indexing.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "IndexOutput"]
type Output: ?Sized;
/// Performs the indexing (`container[index]`) operation.