About condition in which hir::Index will mirror to thir::Index

From this code ,paste here

hir::ExprKind::Index(ref lhs, ref index) => {
  if cx.typeck_results().is_method_call(expr) {
    overloaded_place(cx, expr, expr_ty, None, vec![lhs.to_ref(), index.to_ref()])
  } else {
    ExprKind::Index { lhs: lhs.to_ref(), index: index.to_ref() } 

And from here , an hir::Index expression must implement Index trait to pass the check.

So my question is how to make compiler go through the else part? That is to mirror hir::Index to thir::Index instead of thir::Call ?

I guess there must some thing happening (for example delete the method call from the type check results) between after type check and the mirroring. Many thanks!

If you didn't overload the index operator for lhs then it will lower to ExprKind::Index. The implementations of many operator traits for builtin types are not considered as overloading. In fact you can write anything you want in the method body and it will still perform the builtin operation unless you explicitly write a method call. In most cases the method bodies of those impls are directly using the operator they "overload". For example

aha , I found it at here :joy:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.