Skip to content

Commit 3ae669d

Browse files
committed
check if T is slice
fix msg
1 parent 06f89b7 commit 3ae669d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,14 +2943,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
29432943
) {
29442944
if let ObligationCauseCode::ImplDerivedObligation(_) = obligation.cause.code()
29452945
&& self.tcx.is_diagnostic_item(sym::SliceIndex, trait_pred.skip_binder().trait_ref.def_id)
2946+
&& let ty::Slice(_) = trait_pred.skip_binder().trait_ref.substs.type_at(1).kind()
29462947
&& let ty::Ref(_, inner_ty, _) = trait_pred.skip_binder().self_ty().kind()
29472948
&& let ty::Uint(ty::UintTy::Usize) = inner_ty.kind()
29482949
{
29492950
err.span_suggestion_verbose(
29502951
obligation.cause.span.shrink_to_lo(),
2951-
"consider dereferencing here",
2952+
"dereference this index",
29522953
'*',
2953-
Applicability::MaybeIncorrect,
2954+
Applicability::MachineApplicable,
29542955
);
29552956
}
29562957
}

src/test/ui/suggestions/suggest-dereferencing-index.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let one_item_please: i32 = [1, 2, 3][i];
77
= help: the trait `SliceIndex<[{integer}]>` is not implemented for `&usize`
88
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
99
= note: required because of the requirements on the impl of `Index<&usize>` for `[{integer}]`
10-
help: consider dereferencing here
10+
help: dereference this index
1111
|
1212
LL | let one_item_please: i32 = [1, 2, 3][*i];
1313
| +

0 commit comments

Comments
 (0)