intellij-rust: Quick fixes on type mismatch

A very basic type checking just merged #1727 Now it’s possible to attach quick fixes to a type mismatch annotations (on this line). I can imagine the following quick fixes (we assume that A is actual type, B is expected type and so a is a var of type A. e.g. let a: A = ...; let _: B = a;):

Coercions:

  • If both types are numerics, we can suggest to add a cast a as B.
  • We can have a set of special cases like str.to_string()/String.as_str()
  • We can try to find impl From<A> for B, and if it is exists, suggest B::from(a)
  • From is not the one type conversion trait. We can also deal with ToOwned/AsRef/AsMut/Borrow/BorrowMut or even TryFrom/FromStr
  • We can try to deref *a to match required type
  • We can also get more references &a/&mut a
  • And any combinations of these, like &*a
  • Or even &S::from(*a)

Refactorings:

You can find examples of quick fixes in the org.rust.ide.annotator.fixes package.


You can find more info about how to start contributing to Intellij-Rust in CONTRIBUTING.md, and some info about our architecure in ARCHITECTURE.md. If you have any questions about this issue, you can ask them right here or in our gitter. If you decided to grab this issue, please leave a comment here and put yourself in the worklist.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks @vlad20012, no prob, hope you feel better now. Cool, I’ll add the simple cases first.