Skip to content

Commit

Permalink
check if T is slice
Browse files Browse the repository at this point in the history
fix msg
  • Loading branch information
TaKO8Ki committed Jul 29, 2022
1 parent 06f89b7 commit 3ae669d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2943,14 +2943,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
) {
if let ObligationCauseCode::ImplDerivedObligation(_) = obligation.cause.code()
&& self.tcx.is_diagnostic_item(sym::SliceIndex, trait_pred.skip_binder().trait_ref.def_id)
&& let ty::Slice(_) = trait_pred.skip_binder().trait_ref.substs.type_at(1).kind()
&& let ty::Ref(_, inner_ty, _) = trait_pred.skip_binder().self_ty().kind()
&& let ty::Uint(ty::UintTy::Usize) = inner_ty.kind()
{
err.span_suggestion_verbose(
obligation.cause.span.shrink_to_lo(),
"consider dereferencing here",
"dereference this index",
'*',
Applicability::MaybeIncorrect,
Applicability::MachineApplicable,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/suggestions/suggest-dereferencing-index.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | let one_item_please: i32 = [1, 2, 3][i];
= help: the trait `SliceIndex<[{integer}]>` is not implemented for `&usize`
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required because of the requirements on the impl of `Index<&usize>` for `[{integer}]`
help: consider dereferencing here
help: dereference this index
|
LL | let one_item_please: i32 = [1, 2, 3][*i];
| +
Expand Down

0 comments on commit 3ae669d

Please sign in to comment.