Skip to content

Commit d84b5f9

Browse files
Use a diagnostic item instead of filtering for Index::Output
1 parent 770c303 commit d84b5f9

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -2871,6 +2871,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28712871
base_ty: Ty<'tcx>,
28722872
) -> Option<(ErrorGuaranteed, Ty<'tcx>, Ty<'tcx>)> {
28732873
let index_trait_def_id = self.tcx.lang_items().index_trait()?;
2874+
let index_trait_output_def_id = self.tcx.get_diagnostic_item(sym::IndexOutput)?;
28742875

28752876
let mut relevant_impls = vec![];
28762877
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> {
29172918
let element_ty = ocx.normalize(
29182919
&cause,
29192920
self.param_env,
2920-
self.tcx.mk_projection(
2921-
self.tcx
2922-
.associated_items(index_trait_def_id)
2923-
.filter_by_name_unhygienic(sym::Output)
2924-
.next()
2925-
.unwrap()
2926-
.def_id,
2927-
impl_trait_ref.substs,
2928-
),
2921+
self.tcx.mk_projection(index_trait_output_def_id, impl_trait_ref.substs),
29292922
);
29302923

29312924
let errors = ocx.select_where_possible();

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ symbols! {
204204
HashSet,
205205
Hasher,
206206
Implied,
207+
IndexOutput,
207208
Input,
208209
Into,
209210
IntoDiagnostic,

library/core/src/ops/index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
pub trait Index<Idx: ?Sized> {
6060
/// The returned type after indexing.
6161
#[stable(feature = "rust1", since = "1.0.0")]
62+
#[rustc_diagnostic_item = "IndexOutput"]
6263
type Output: ?Sized;
6364

6465
/// Performs the indexing (`container[index]`) operation.

0 commit comments

Comments
 (0)